summaryrefslogtreecommitdiff
path: root/lib/libalpm
diff options
context:
space:
mode:
authorDan McGee <dan@archlinux.org>2007-02-26 23:32:08 +0000
committerDan McGee <dan@archlinux.org>2007-02-26 23:32:08 +0000
commitcb311adeab04aa5a8780f48af450b5e20a00dedc (patch)
tree3bbb0cb576b543894814c3d22a4ff2d964b26c5e /lib/libalpm
parent01bb564e703ab8cbff26940f9274484f1a3ad87b (diff)
downloadpacman-cb311adeab04aa5a8780f48af450b5e20a00dedc.tar.xz
* db search optimization- why don't we compile the regex once instead of once
per package.
Diffstat (limited to 'lib/libalpm')
-rw-r--r--lib/libalpm/db.c18
1 files changed, 11 insertions, 7 deletions
diff --git a/lib/libalpm/db.c b/lib/libalpm/db.c
index 8a7210d3..62255a3f 100644
--- a/lib/libalpm/db.c
+++ b/lib/libalpm/db.c
@@ -105,21 +105,21 @@ alpm_list_t *_alpm_db_search(pmdb_t *db, alpm_list_t *needles)
for(i = needles; i; i = i->next) {
char *targ;
+ regex_t reg;
if(i->data == NULL) {
continue;
}
targ = i->data;
_alpm_log(PM_LOG_DEBUG, "searching for target '%s'", targ);
+
+ if(regcomp(&reg, targ, REG_EXTENDED | REG_NOSUB | REG_ICASE | REG_NEWLINE) != 0) {
+ RET_ERR(PM_ERR_INVALID_REGEX, NULL);
+ }
for(j = _alpm_db_get_pkgcache(db, INFRQ_DESC|INFRQ_DEPENDS); j; j = j->next) {
pmpkg_t *pkg = j->data;
char *matched = NULL;
- regex_t reg;
-
- if(regcomp(&reg, targ, REG_EXTENDED | REG_NOSUB | REG_ICASE | REG_NEWLINE) != 0) {
- RET_ERR(PM_ERR_INVALID_REGEX, NULL);
- }
/* check name */
if (regexec(&reg, pkg->name, 0, 0, 0) == 0) {
@@ -130,6 +130,8 @@ alpm_list_t *_alpm_db_search(pmdb_t *db, alpm_list_t *needles)
matched = pkg->desc;
}
/* check provides */
+ /* TODO: should we be doing this, and should we print something
+ * differently when we do match it since it isn't currently printed? */
else {
for(k = pkg->provides; k; k = k->next) {
if (regexec(&reg, k->data, 0, 0, 0) == 0) {
@@ -138,13 +140,15 @@ alpm_list_t *_alpm_db_search(pmdb_t *db, alpm_list_t *needles)
}
}
}
- regfree(&reg);
if(matched != NULL) {
- _alpm_log(PM_LOG_DEBUG, " search target '%s' matched '%s'", targ, matched);
+ _alpm_log(PM_LOG_DEBUG, " search target '%s' matched '%s'",
+ targ, matched);
ret = alpm_list_add(ret, pkg);
}
}
+
+ regfree(&reg);
}
return(ret);