xbps-query: optimize the search mode with --regex (compile ERE once).
This commit is contained in:
parent
8263449f94
commit
676888b5c1
2
NEWS
2
NEWS
@ -23,7 +23,7 @@ xbps-0.44 (???):
|
||||
and its dependencies) and `xbps-remove -o` (remove orphaned pkgs) marginally.
|
||||
|
||||
* xbps-query(8): only compile the ERE (Extended Regular Expression) once in
|
||||
the ownedby mode. A performance improvement suggested by Christian Neukirchen.
|
||||
the ownedby and search modes. A performance improvement suggested by Christian Neukirchen.
|
||||
|
||||
* libxbps: performance improvement for xbps_repo_get_pkg_revdeps(): when finding
|
||||
the matching pkg, search for it in the current repository, not in the repository
|
||||
|
@ -45,6 +45,7 @@
|
||||
|
||||
struct search_data {
|
||||
bool regex, repo_mode;
|
||||
regex_t regexp;
|
||||
int maxcols;
|
||||
const char *pat, *prop, *repourl;
|
||||
xbps_array_t results;
|
||||
@ -104,7 +105,6 @@ search_array_cb(struct xbps_handle *xhp _unused,
|
||||
xbps_object_t obj2;
|
||||
struct search_data *sd = arg;
|
||||
const char *pkgver = NULL, *desc, *str;
|
||||
regex_t regex;
|
||||
|
||||
if (!xbps_dictionary_get_cstring_nocopy(obj, "pkgver", &pkgver))
|
||||
return 0;
|
||||
@ -118,15 +118,11 @@ search_array_cb(struct xbps_handle *xhp _unused,
|
||||
vpkgfound = true;
|
||||
|
||||
if (sd->regex) {
|
||||
if (regcomp(®ex, sd->pat, REG_EXTENDED|REG_NOSUB) != 0)
|
||||
return errno;
|
||||
|
||||
if ((regexec(®ex, pkgver, 0, 0, 0) == 0) ||
|
||||
(regexec(®ex, desc, 0, 0, 0) == 0)) {
|
||||
if ((regexec(&sd->regexp, pkgver, 0, 0, 0) == 0) ||
|
||||
(regexec(&sd->regexp, desc, 0, 0, 0) == 0)) {
|
||||
xbps_array_add_cstring_nocopy(sd->results, pkgver);
|
||||
xbps_array_add_cstring_nocopy(sd->results, desc);
|
||||
}
|
||||
regfree(®ex);
|
||||
return 0;
|
||||
}
|
||||
if (vpkgfound) {
|
||||
@ -149,15 +145,12 @@ search_array_cb(struct xbps_handle *xhp _unused,
|
||||
for (unsigned int i = 0; i < xbps_array_count(obj2); i++) {
|
||||
xbps_array_get_cstring_nocopy(obj2, i, &str);
|
||||
if (sd->regex) {
|
||||
if (regcomp(®ex, sd->pat, REG_EXTENDED|REG_NOSUB) != 0)
|
||||
return errno;
|
||||
if (regexec(®ex, str, 0, 0, 0) == 0) {
|
||||
if (regexec(&sd->regexp, str, 0, 0, 0) == 0) {
|
||||
if (sd->repo_mode)
|
||||
printf("%s: %s (%s)\n", pkgver, str, sd->repourl);
|
||||
else
|
||||
printf("%s: %s\n", pkgver, str);
|
||||
}
|
||||
regfree(®ex);
|
||||
} else {
|
||||
if ((strcasestr(str, sd->pat)) ||
|
||||
(fnmatch(sd->pat, str, FNM_PERIOD)) == 0) {
|
||||
@ -176,15 +169,12 @@ search_array_cb(struct xbps_handle *xhp _unused,
|
||||
exit(EXIT_FAILURE);
|
||||
|
||||
if (sd->regex) {
|
||||
if (regcomp(®ex, sd->pat, REG_EXTENDED|REG_NOSUB) != 0)
|
||||
return errno;
|
||||
if (regexec(®ex, size, 0, 0, 0) == 0) {
|
||||
if (regexec(&sd->regexp, size, 0, 0, 0) == 0) {
|
||||
if (sd->repo_mode)
|
||||
printf("%s: %s (%s)\n", pkgver, size, sd->repourl);
|
||||
else
|
||||
printf("%s: %s\n", pkgver, size);
|
||||
}
|
||||
regfree(®ex);
|
||||
} else {
|
||||
if (strcasestr(size, sd->pat)) {
|
||||
if (sd->repo_mode)
|
||||
@ -204,15 +194,12 @@ search_array_cb(struct xbps_handle *xhp _unused,
|
||||
/* property is a string */
|
||||
str = xbps_string_cstring_nocopy(obj2);
|
||||
if (sd->regex) {
|
||||
if (regcomp(®ex, sd->pat, REG_EXTENDED|REG_NOSUB) != 0)
|
||||
return errno;
|
||||
if (regexec(®ex, str, 0, 0, 0) == 0) {
|
||||
if (regexec(&sd->regexp, str, 0, 0, 0) == 0) {
|
||||
if (sd->repo_mode)
|
||||
printf("%s: %s (%s)\n", pkgver, str, sd->repourl);
|
||||
else
|
||||
printf("%s: %s\n", pkgver, str);
|
||||
}
|
||||
regfree(®ex);
|
||||
} else {
|
||||
if (strcasestr(str, sd->pat)) {
|
||||
if (sd->repo_mode)
|
||||
@ -249,6 +236,10 @@ search(struct xbps_handle *xhp, bool repo_mode, const char *pat, const char *pro
|
||||
int rv;
|
||||
|
||||
sd.regex = regex;
|
||||
if (regex) {
|
||||
if (regcomp(&sd.regexp, pat, REG_EXTENDED|REG_NOSUB) != 0)
|
||||
return errno;
|
||||
}
|
||||
sd.repo_mode = repo_mode;
|
||||
sd.pat = pat;
|
||||
sd.prop = prop;
|
||||
@ -274,6 +265,8 @@ search(struct xbps_handle *xhp, bool repo_mode, const char *pat, const char *pro
|
||||
print_results(xhp, &sd);
|
||||
xbps_object_release(sd.results);
|
||||
}
|
||||
if (regex)
|
||||
regfree(&sd.regexp);
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user