Skip to main content.
home | support | download

Back to List Archive

Performance - regcomp

From: Julian Perry <jules(at)>
Date: Tue Feb 29 2000 - 11:24:57 GMT

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;
	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
      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

Received on Tue Feb 29 06:32:30 2000