diff options
author | Timo Sirainen <cras@irssi.org> | 2000-11-07 00:06:35 +0000 |
---|---|---|
committer | cras <cras@dbcabf3a-b0e7-0310-adc4-f8d773084564> | 2000-11-07 00:06:35 +0000 |
commit | 4301e0479124953c1e78c4a150433571188fdc8d (patch) | |
tree | 8ae11e35af83dcfebb31223859079e41a002c671 /src/core | |
parent | 6cc6f90468db71e38ca918d7360265d09a8dee7c (diff) | |
download | irssi-4301e0479124953c1e78c4a150433571188fdc8d.zip |
Regexp ignores are now compiled when they're created, not every time
they're checked (every time a new line is received). This should reduce
some CPU load when using them.
git-svn-id: http://svn.irssi.org/repos/irssi/trunk@812 dbcabf3a-b0e7-0310-adc4-f8d773084564
Diffstat (limited to 'src/core')
-rw-r--r-- | src/core/ignore.c | 16 | ||||
-rw-r--r-- | src/core/ignore.h | 7 |
2 files changed, 20 insertions, 3 deletions
diff --git a/src/core/ignore.c b/src/core/ignore.c index 5c37fe45..9ff6ce98 100644 --- a/src/core/ignore.c +++ b/src/core/ignore.c @@ -122,9 +122,14 @@ int ignore_check(SERVER_REC *server, const char *nick, const char *host, if (patt_len <= best_patt) continue; } - ok = rec->regexp ? regexp_match(text, rec->pattern) : - rec->fullword ? stristr_full(text, rec->pattern) != NULL : - stristr(text, rec->pattern) != NULL; + if (rec->regexp) { + ok = !rec->regexp_compiled ? FALSE : + regexec(&rec->preg, text, 0, NULL, 0) == 0; + } else { + ok = rec->fullword ? + stristr_full(text, rec->pattern) != NULL : + stristr(text, rec->pattern) != NULL; + } if (!ok) continue; } @@ -257,6 +262,10 @@ static void ignore_remove_config(IGNORE_REC *rec) void ignore_add_rec(IGNORE_REC *rec) { + rec->regexp_compiled = !rec->regexp || rec->pattern == NULL ? FALSE : + regcomp(&rec->preg, rec->pattern, + REG_EXTENDED|REG_ICASE|REG_NOSUB) == 0; + ignores = g_slist_append(ignores, rec); ignore_set_config(rec); @@ -268,6 +277,7 @@ static void ignore_destroy(IGNORE_REC *rec) ignores = g_slist_remove(ignores, rec); signal_emit("ignore destroyed", 1, rec); + if (rec->regexp_compiled) regfree(&rec->preg); if (rec->time_tag > 0) g_source_remove(rec->time_tag); if (rec->channels != NULL) g_strfreev(rec->channels); g_free_not_null(rec->mask); diff --git a/src/core/ignore.h b/src/core/ignore.h index c52e09ba..6c336c00 100644 --- a/src/core/ignore.h +++ b/src/core/ignore.h @@ -2,6 +2,9 @@ #define __IGNORE_H #include "servers.h" +#ifdef HAVE_REGEX_H +# include <regex.h> +#endif typedef struct { char *mask; /* nick mask */ @@ -18,6 +21,10 @@ typedef struct { int regexp:1; int fullword:1; int replies:1; /* ignore replies to nick in channel */ +#ifdef HAVE_REGEX_H + int regexp_compiled:1; /* should always be TRUE, unless regexp is invalid */ + regex_t preg; +#endif } IGNORE_REC; extern GSList *ignores; |