Commit ec497df1 authored by Wayne Davison's avatar Wayne Davison

Optimized set_compression() to remove the per-file strdup(), strlower(),

and free() calls (it now uses iwildmatch()).
parent 8e744636
...@@ -24,48 +24,58 @@ extern int do_compression; ...@@ -24,48 +24,58 @@ extern int do_compression;
extern int module_id; extern int module_id;
extern int def_compress_level; extern int def_compress_level;
static int compression_level; static int compression_level, per_file_default_level;
/* determine the compression level based on a wildcard filename list */ /* determine the compression level based on a wildcard filename list */
void set_compression(char *fname) void set_compression(char *fname)
{ {
char *dont; static char *match_list;
char *tok; char *s;
if (!do_compression) if (!do_compression)
return; return;
compression_level = def_compress_level; if (!match_list) {
dont = lp_dont_compress(module_id); char *t, *f = lp_dont_compress(module_id);
int len = strlen(f);
if (!dont || !*dont) if (!(match_list = t = new_array(char, len + 2)))
return; out_of_memory("set_compression");
while (*f) {
if (dont[0] == '*' && !dont[1]) { if (*f == ' ') {
/* an optimization to skip the rest of this routine */ f++;
compression_level = 0; continue;
return; }
do {
if (isupper(*(unsigned char *)f))
*t++ = tolower(*(unsigned char *)f);
else
*t++ = *f;
} while (*++f != ' ' && *f);
*t++ = '\0';
}
/* Optimize a match-string of "*". */
if (t - match_list == 2 && match_list[0] == '*') {
t = match_list;
per_file_default_level = 0;
} else
per_file_default_level = def_compress_level;
*t++ = '\0';
} }
if ((tok = strrchr(fname, '/')) != NULL) compression_level = per_file_default_level;
fname = tok + 1;
dont = strdup(dont); if (!*match_list)
fname = strdup(fname);
if (!dont || !fname)
return; return;
strlower(dont); if ((s = strrchr(fname, '/')) != NULL)
strlower(fname); fname = s + 1;
for (tok = strtok(dont, " "); tok; tok = strtok(NULL, " ")) { for (s = match_list; *s; s += strlen(s) + 1) {
if (wildmatch(tok, fname)) { if (iwildmatch(s, fname)) {
compression_level = 0; compression_level = 0;
break; break;
} }
} }
free(dont);
free(fname);
} }
/* non-compressing recv token */ /* non-compressing recv token */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment