summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTimo Teräs <timo.teras@iki.fi>2013-06-13 21:18:40 +0300
committerTimo Teräs <timo.teras@iki.fi>2013-06-13 21:19:30 +0300
commit2ff59b7c23d81d819d8b2dc3268ee70f0cb4d71b (patch)
tree2b63d914bdb023dda54b5e4b98b00dcbfbc5c670
parentf4ce2bf4c4b62779b097c8030feac09ffbda0c3a (diff)
downloadapk-tools-2ff59b7c23d81d819d8b2dc3268ee70f0cb4d71b.tar.gz
apk-tools-2ff59b7c23d81d819d8b2dc3268ee70f0cb4d71b.tar.bz2
apk-tools-2ff59b7c23d81d819d8b2dc3268ee70f0cb4d71b.tar.xz
apk-tools-2ff59b7c23d81d819d8b2dc3268ee70f0cb4d71b.zip
search: speed up searching exact package names
-rw-r--r--src/search.c42
1 files changed, 26 insertions, 16 deletions
diff --git a/src/search.c b/src/search.c
index b31859d..9ef61a1 100644
--- a/src/search.c
+++ b/src/search.c
@@ -97,7 +97,7 @@ static int search_parse(void *ctx, struct apk_db_options *dbopts,
return 0;
}
-static void print_result(struct search_ctx *ctx, struct apk_package *pkg)
+static void print_result_pkg(struct search_ctx *ctx, struct apk_package *pkg)
{
int i;
@@ -117,23 +117,13 @@ static void print_result(struct search_ctx *ctx, struct apk_package *pkg)
ctx->print_result(ctx, pkg);
}
-static int match_names(apk_hash_item item, void *pctx)
+static void print_result(struct search_ctx *ctx, struct apk_name *name)
{
- struct search_ctx *ctx = (struct search_ctx *) pctx;
- struct apk_name *name = (struct apk_name *) item;
int i;
- if (!ctx->search_description) {
- for (i = 0; i < ctx->argc; i++)
- if (fnmatch(ctx->argv[i], name->name, FNM_CASEFOLD) == 0)
- break;
- if (ctx->argc > 0 && i >= ctx->argc)
- return 0;
- }
-
if (ctx->show_all) {
for (i = 0; i < name->providers->num; i++)
- print_result(ctx, name->providers->item[i].pkg);
+ print_result_pkg(ctx, name->providers->item[i].pkg);
} else {
struct apk_package *pkg = NULL;
struct apk_provider *p;
@@ -144,8 +134,25 @@ static int match_names(apk_hash_item item, void *pctx)
apk_version_compare_blob(*p->version, *version) == APK_VERSION_GREATER)
pkg = p->pkg;
}
- print_result(ctx, pkg);
+ print_result_pkg(ctx, pkg);
}
+}
+
+static int match_names(apk_hash_item item, void *pctx)
+{
+ struct search_ctx *ctx = (struct search_ctx *) pctx;
+ struct apk_name *name = (struct apk_name *) item;
+ int i;
+
+ if (!ctx->search_description) {
+ for (i = 0; i < ctx->argc; i++)
+ if (fnmatch(ctx->argv[i], name->name, FNM_CASEFOLD) == 0)
+ break;
+ if (ctx->argc > 0 && i >= ctx->argc)
+ return 0;
+ }
+ print_result(ctx, name);
+
return 0;
}
@@ -175,8 +182,11 @@ static int search_main(void *pctx, struct apk_database *db, int argc, char **arg
}
} else {
ctx->argv = argv;
- /* FIXME: if not searching descriptions, we can just
- * do direct name lookups here */
+ if (!ctx->search_description) {
+ for (i = 0; i < argc; i++)
+ print_result(ctx, apk_db_get_name(db, APK_BLOB_STR(argv[i])));
+ return 0;
+ }
}
return apk_hash_foreach(&db->available.names, match_names, ctx);