diff options
author | Timo Teräs <timo.teras@iki.fi> | 2010-08-13 10:17:31 +0300 |
---|---|---|
committer | Timo Teräs <timo.teras@iki.fi> | 2010-08-13 10:17:31 +0300 |
commit | 8bc76c78a69360efc7a07a3c4e92f393cca22543 (patch) | |
tree | 447d60cf98355698ef9d6ad2480550b0d71ed266 /squarkdb.c | |
parent | e0a013397a51963039c43877be3afe954e519be0 (diff) | |
download | squark-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 'squarkdb.c')
-rw-r--r-- | squarkdb.c | 16 |
1 files changed, 16 insertions, 0 deletions
@@ -138,3 +138,19 @@ void *sqdb_section_get(struct sqdb *db, int id, uint32_t *size) return db->mmap_base + hdr->section[id].offset; } +blob_t sqdb_get_string_literal(struct sqdb *db, uint32_t encoded_ptr) +{ + unsigned char *ptr; + unsigned int len, off; + + ptr = sqdb_section_get(db, SQDB_SECTION_STRINGS, NULL); + if (ptr == NULL) + return BLOB_NULL; + + off = encoded_ptr >> SQDB_LENGTH_BITS; + len = encoded_ptr & ((1 << SQDB_LENGTH_BITS) - 1); + if (len == 0) + len = ptr[off++]; + + return BLOB_PTR_LEN(ptr + off, len); +} |