summaryrefslogtreecommitdiffstats
path: root/squark-filter.c
diff options
context:
space:
mode:
authorTimo Teräs <timo.teras@iki.fi>2010-08-13 10:17:31 +0300
committerTimo Teräs <timo.teras@iki.fi>2010-08-13 10:17:31 +0300
commit8bc76c78a69360efc7a07a3c4e92f393cca22543 (patch)
tree447d60cf98355698ef9d6ad2480550b0d71ed266 /squark-filter.c
parente0a013397a51963039c43877be3afe954e519be0 (diff)
downloadsquark-8bc76c78a69360efc7a07a3c4e92f393cca22543.tar.bz2
squark-8bc76c78a69360efc7a07a3c4e92f393cca22543.tar.xz
db: smarter string pointer encoding (include length field)
So we don't need explicit null terminator in most cases saving space. It will also speed up comparisons as getting string blob is now constant time (no strlen needed).
Diffstat (limited to 'squark-filter.c')
-rw-r--r--squark-filter.c8
1 files changed, 3 insertions, 5 deletions
diff --git a/squark-filter.c b/squark-filter.c
index 8973d04..e47cbf5 100644
--- a/squark-filter.c
+++ b/squark-filter.c
@@ -112,12 +112,10 @@ static blob_t url_classify(struct url_info *url, struct sqdb *db)
void *cmph;
struct sqdb_index_entry *indx;
uint32_t *categories;
- char *strings;
cmph_uint32 i = -1, previ;
cmph = sqdb_section_get(db, SQDB_SECTION_INDEX_MPH, NULL);
indx = sqdb_section_get(db, SQDB_SECTION_INDEX, NULL);
- strings = sqdb_section_get(db, SQDB_SECTION_STRINGS, NULL);
/* search for most qualified domain match; do first lookup
* with two domain components */
@@ -132,14 +130,14 @@ static blob_t url_classify(struct url_info *url, struct sqdb *db)
previ = i;
i = cmph_search_packed(cmph, key.ptr, key.len);
- if (blob_cmp(got, BLOB_STR(&strings[indx[i].component])) != 0) {
+ if (blob_cmp(got, sqdb_get_string_literal(db, indx[i].component)) != 0) {
/* the subdomain did no longer match, use
* parents classification */
i = previ;
goto parent_dns_match;
}
if (!blob_is_null(tld)) {
- if (blob_cmp(tld, BLOB_STR(&strings[indx[indx[i].parent].component])) != 0) {
+ if (blob_cmp(tld, sqdb_get_string_literal(db, indx[indx[i].parent].component)) != 0) {
/* top level domain did not match */
i = -1;
goto parent_dns_match;
@@ -163,7 +161,7 @@ parent_dns_match:
categories = sqdb_section_get(db, SQDB_SECTION_CATEGORIES, NULL);
printf("%d\n", indx[i].category);
- return BLOB_STR(&strings[categories[indx[i].category]]);
+ return sqdb_get_string_literal(db, categories[indx[i].category]);
}
int main(int argc, char **argv)