Skip to main content.
home | support | download

Back to List Archive

Performance - regcomp

From: Julian Perry <jules(at)not-real.limitless.co.uk>
Date: Tue Feb 29 2000 - 11:24:57 GMT
Hi

Just looking at how swish-e uses regcomp and
regexec, three issues spring to mind:

1)  There are some terrible memory leaks
    as the space isn't regfree'd - this has been
    noticed by others and patches exist.  But
    this free'ing can be avoided as it isn't
    required ...

2)  Performance could be improved by saving the
    data returned from regcomp and using it
    again rather than recompiling the same regular
    expressions over and over again.  This could
    be done (for example), by changing:
	struct swline {
	        char *line;
	        struct swline *next;
	};
    to
	struct swline {
	        char *line;
	        regex_t re;
	        struct swline *next;
	};
    and then use like this:
        if (!list->re)
	{
        	status = regcomp(&list->re, list->line, REG_EXTENDED);
        	if ( status != 0)
                	return 0;
	}
    Clearly there are other code changes required as matchARegex
    currently is passed just 'line' and not the structure
    'swline' which would be needed for this scheme to work.

3)  The example config files give entries like
    this:
      FileRules filename contains # % ~ .bak .orig .old old.
      FileRules directory contains .htaccess
    and as regex's are involved, these should be:
      FileRules filename contains # % ~ \.bak \.orig \.old old\.
      FileRules directory contains \.htaccess

Comments?
-- 
Cheers
Jules.
Received on Tue Feb 29 06:32:30 2000