mirror of
https://github.com/moparisthebest/pacman
synced 2024-08-13 17:03:46 -04:00
* db search optimization- why don't we compile the regex once instead of once
per package.
This commit is contained in:
parent
01bb564e70
commit
cb311adeab
@ -105,6 +105,7 @@ alpm_list_t *_alpm_db_search(pmdb_t *db, alpm_list_t *needles)
|
|||||||
|
|
||||||
for(i = needles; i; i = i->next) {
|
for(i = needles; i; i = i->next) {
|
||||||
char *targ;
|
char *targ;
|
||||||
|
regex_t reg;
|
||||||
|
|
||||||
if(i->data == NULL) {
|
if(i->data == NULL) {
|
||||||
continue;
|
continue;
|
||||||
@ -112,14 +113,13 @@ alpm_list_t *_alpm_db_search(pmdb_t *db, alpm_list_t *needles)
|
|||||||
targ = i->data;
|
targ = i->data;
|
||||||
_alpm_log(PM_LOG_DEBUG, "searching for target '%s'", targ);
|
_alpm_log(PM_LOG_DEBUG, "searching for target '%s'", targ);
|
||||||
|
|
||||||
|
if(regcomp(®, 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) {
|
for(j = _alpm_db_get_pkgcache(db, INFRQ_DESC|INFRQ_DEPENDS); j; j = j->next) {
|
||||||
pmpkg_t *pkg = j->data;
|
pmpkg_t *pkg = j->data;
|
||||||
char *matched = NULL;
|
char *matched = NULL;
|
||||||
regex_t reg;
|
|
||||||
|
|
||||||
if(regcomp(®, targ, REG_EXTENDED | REG_NOSUB | REG_ICASE | REG_NEWLINE) != 0) {
|
|
||||||
RET_ERR(PM_ERR_INVALID_REGEX, NULL);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* check name */
|
/* check name */
|
||||||
if (regexec(®, pkg->name, 0, 0, 0) == 0) {
|
if (regexec(®, 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;
|
matched = pkg->desc;
|
||||||
}
|
}
|
||||||
/* check provides */
|
/* 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 {
|
else {
|
||||||
for(k = pkg->provides; k; k = k->next) {
|
for(k = pkg->provides; k; k = k->next) {
|
||||||
if (regexec(®, k->data, 0, 0, 0) == 0) {
|
if (regexec(®, k->data, 0, 0, 0) == 0) {
|
||||||
@ -138,13 +140,15 @@ alpm_list_t *_alpm_db_search(pmdb_t *db, alpm_list_t *needles)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
regfree(®);
|
|
||||||
|
|
||||||
if(matched != NULL) {
|
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);
|
ret = alpm_list_add(ret, pkg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
regfree(®);
|
||||||
}
|
}
|
||||||
|
|
||||||
return(ret);
|
return(ret);
|
||||||
|
Loading…
Reference in New Issue
Block a user