1
0
mirror of https://github.com/irssi/irssi.git synced 2024-12-04 14:46:39 -05:00

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
This commit is contained in:
Timo Sirainen 2000-11-07 00:06:35 +00:00 committed by cras
parent 6cc6f90468
commit 4301e04791
2 changed files with 20 additions and 3 deletions

View File

@ -122,9 +122,14 @@ int ignore_check(SERVER_REC *server, const char *nick, const char *host,
if (patt_len <= best_patt) continue; if (patt_len <= best_patt) continue;
} }
ok = rec->regexp ? regexp_match(text, rec->pattern) : if (rec->regexp) {
rec->fullword ? stristr_full(text, rec->pattern) != NULL : 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; stristr(text, rec->pattern) != NULL;
}
if (!ok) continue; if (!ok) continue;
} }
@ -257,6 +262,10 @@ static void ignore_remove_config(IGNORE_REC *rec)
void ignore_add_rec(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); ignores = g_slist_append(ignores, rec);
ignore_set_config(rec); ignore_set_config(rec);
@ -268,6 +277,7 @@ static void ignore_destroy(IGNORE_REC *rec)
ignores = g_slist_remove(ignores, rec); ignores = g_slist_remove(ignores, rec);
signal_emit("ignore destroyed", 1, 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->time_tag > 0) g_source_remove(rec->time_tag);
if (rec->channels != NULL) g_strfreev(rec->channels); if (rec->channels != NULL) g_strfreev(rec->channels);
g_free_not_null(rec->mask); g_free_not_null(rec->mask);

View File

@ -2,6 +2,9 @@
#define __IGNORE_H #define __IGNORE_H
#include "servers.h" #include "servers.h"
#ifdef HAVE_REGEX_H
# include <regex.h>
#endif
typedef struct { typedef struct {
char *mask; /* nick mask */ char *mask; /* nick mask */
@ -18,6 +21,10 @@ typedef struct {
int regexp:1; int regexp:1;
int fullword:1; int fullword:1;
int replies:1; /* ignore replies to nick in channel */ 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; } IGNORE_REC;
extern GSList *ignores; extern GSList *ignores;