tdb2: minor optimization for set_header
authorRusty Russell <rusty@rustcorp.com.au>
Mon, 15 Nov 2010 07:19:11 +0000 (17:49 +1030)
committerRusty Russell <rusty@rustcorp.com.au>
Mon, 15 Nov 2010 07:19:11 +0000 (17:49 +1030)
We actually only need the bottom 5 bits of the hash value, so don't waste
8 bytes passing it.

ccan/tdb2/free.c
ccan/tdb2/private.h

index 2b07fdff330a3dfe23631dd6e98a3effb399e428..e6e77bf616666deed3940b07707616485bd29812 100644 (file)
@@ -516,7 +516,7 @@ static tdb_off_t get_free(struct tdb_context *tdb, size_t size,
 int set_header(struct tdb_context *tdb,
               struct tdb_used_record *rec,
               uint64_t keylen, uint64_t datalen,
-              uint64_t actuallen, uint64_t hash,
+              uint64_t actuallen, unsigned hashlow,
               unsigned int zone_bits)
 {
        uint64_t keybits = (fls64(keylen) + 1) / 2;
@@ -524,7 +524,7 @@ int set_header(struct tdb_context *tdb,
        /* Use bottom bits of hash, so it's independent of hash table size. */
        rec->magic_and_meta
                = zone_bits
-               | ((hash & ((1 << 5)-1)) << 6)
+               | ((hashlow & ((1 << 5)-1)) << 6)
                | ((actuallen - (keylen + datalen)) << 11)
                | (keybits << 43)
                | (TDB_MAGIC << 48);
index 6c727aff4a20a62dc800e5806079742cd32d7ec1..6780fdadd421303ee9aec389cae999b8b96d755c 100644 (file)
@@ -380,7 +380,7 @@ int add_free_record(struct tdb_context *tdb, unsigned int zone_bits,
 int set_header(struct tdb_context *tdb,
               struct tdb_used_record *rec,
               uint64_t keylen, uint64_t datalen,
-              uint64_t actuallen, uint64_t hash,
+              uint64_t actuallen, unsigned hashlow,
               unsigned int zone_bits);
 
 /* Used by tdb_check to verify. */