]> dgit.raspbian.org Git - dovecot.git/commitdiff
[PATCH 06/12] lib-index: Rename crc32 variables/parameters to hash in strmap
authorTimo Sirainen <timo.sirainen@open-xchange.com>
Mon, 13 Apr 2026 10:52:15 +0000 (12:52 +0200)
committerNoah Meyerhans <noahm@debian.org>
Wed, 16 Sep 2026 19:06:35 +0000 (15:06 -0400)
Pure rename - no functional change. The stored 32-bit value is still
produced by crc32_str_nonzero(); only the identifiers change to prepare
for swapping the hash algorithm in the next commit.

recs_crc32 -> recs_hash, hash_key.crc32 -> hash_key.hash,
crc32_r -> hash_r, local crc32 -> hash, *crc32 -> *hashes.

Gbp-Pq: Name 0006-lib-index-Rename-crc32-variables-parameters-to-hash-.patch

src/lib-index/mail-index-strmap.c

index 9ce2de9103fb0cbc409856c3b33749eff7e2e41a..254080dbb736b7bd65cc6f4c27dd69cd36db231d 100644 (file)
@@ -31,7 +31,7 @@ struct mail_index_strmap_view {
        struct mail_index_view *view;
 
        ARRAY_TYPE(mail_index_strmap_rec) recs;
-       ARRAY(uint32_t) recs_crc32;
+       ARRAY(uint32_t) recs_hash;
        struct hash2_table *hash;
 
        mail_index_strmap_key_cmp_t *key_compare;
@@ -74,7 +74,7 @@ struct mail_index_strmap_view_sync {
 
 struct mail_index_strmap_hash_key {
        const char *str;
-       uint32_t crc32;
+       uint32_t hash;
 };
 
 /* renumber the string indexes when highest string idx becomes larger than
@@ -113,7 +113,7 @@ mail_index_strmap_init(struct mail_index *index, const char *suffix)
 
 static bool
 mail_index_strmap_read_rec_next(struct mail_index_strmap_read_context *ctx,
-                               uint32_t *crc32_r);
+                               uint32_t *hash_r);
 
 static void
 mail_index_strmap_set_syscall_error(struct mail_index_strmap *strmap,
@@ -162,7 +162,7 @@ static unsigned int mail_index_strmap_hash_key(const void *_key)
 {
        const struct mail_index_strmap_hash_key *key = _key;
 
-       return key->crc32;
+       return key->hash;
 }
 
 static bool
@@ -197,7 +197,7 @@ mail_index_strmap_view_open(struct mail_index_strmap *strmap,
        view->next_str_idx = 1;
 
        i_array_init(&view->recs, 64);
-       i_array_init(&view->recs_crc32, 64);
+       i_array_init(&view->recs_hash, 64);
        view->hash = hash2_create(0, sizeof(struct mail_index_strmap_rec),
                                  mail_index_strmap_hash_key,
                                  mail_index_strmap_hash_cmp, view);
@@ -212,7 +212,7 @@ void mail_index_strmap_view_close(struct mail_index_strmap_view **_view)
 
        *_view = NULL;
        array_free(&view->recs);
-       array_free(&view->recs_crc32);
+       array_free(&view->recs_hash);
        hash2_destroy(&view->hash);
        i_free(view);
 }
@@ -226,7 +226,7 @@ static void mail_index_strmap_view_reset(struct mail_index_strmap_view *view)
 {
        view->remap_cb(NULL, 0, 0, view->cb_context);
        array_clear(&view->recs);
-       array_clear(&view->recs_crc32);
+       array_clear(&view->recs_hash);
        hash2_clear(view->hash);
 
        view->last_added_uid = 0;
@@ -410,13 +410,13 @@ mail_index_strmap_uid_exists(struct mail_index_strmap_read_context *ctx,
 
 static int
 mail_index_strmap_read_rec_first(struct mail_index_strmap_read_context *ctx,
-                                uint32_t *crc32_r)
+                                uint32_t *hash_r)
 {
        size_t size;
        uint32_t n, i, count, str_idx;
        int ret;
 
-       /* <uid> <n> <crc32>*count <str_idx>*count
+       /* <uid> <n> <hash>*count <str_idx>*count
           where
             n = 0 -> count=1 (only Message-ID:)
             n = 1 -> count=2 (Message-ID: + In-Reply-To:)
@@ -426,11 +426,11 @@ mail_index_strmap_read_rec_first(struct mail_index_strmap_read_context *ctx,
                return -1;
        count = n < 2 ? n + 1 : n;
        /* check that rec_size fits */
-       if (UINT_MAX / (sizeof(ctx->rec.str_idx) + sizeof(*crc32_r)) < count)
+       if (UINT_MAX / (sizeof(ctx->rec.str_idx) + sizeof(*hash_r)) < count)
                return -1;
        ctx->view->total_ref_count += count;
 
-       ctx->rec_size = count * (sizeof(ctx->rec.str_idx) + sizeof(*crc32_r));
+       ctx->rec_size = count * (sizeof(ctx->rec.str_idx) + sizeof(*hash_r));
        ret = mail_index_strmap_uid_exists(ctx, ctx->rec.uid);
        if (ret < 0)
                return -1;
@@ -454,10 +454,10 @@ mail_index_strmap_read_rec_first(struct mail_index_strmap_read_context *ctx,
        /* everything exists. save it. FIXME: these ref_index values
           are thread index specific, perhaps something more generic
           should be used some day */
-       ctx->end = ctx->data + count * sizeof(*crc32_r);
+       ctx->end = ctx->data + count * sizeof(*hash_r);
 
        ctx->next_ref_index = 0;
-       if (!mail_index_strmap_read_rec_next(ctx, crc32_r))
+       if (!mail_index_strmap_read_rec_next(ctx, hash_r))
                i_unreached();
        ctx->next_ref_index = n == 1 ? 1 : 2;
        return 1;
@@ -465,7 +465,7 @@ mail_index_strmap_read_rec_first(struct mail_index_strmap_read_context *ctx,
 
 static bool
 mail_index_strmap_read_rec_next(struct mail_index_strmap_read_context *ctx,
-                               uint32_t *crc32_r)
+                               uint32_t *hash_r)
 {
        if (ctx->data == ctx->end) {
                i_stream_skip(ctx->view->strmap->input, ctx->rec_size);
@@ -478,7 +478,7 @@ mail_index_strmap_read_rec_next(struct mail_index_strmap_read_context *ctx,
 
        /* read the record contents */
        memcpy(&ctx->rec.str_idx, ctx->str_idx_base, sizeof(ctx->rec.str_idx));
-       memcpy(crc32_r, ctx->data, sizeof(*crc32_r));
+       memcpy(hash_r, ctx->data, sizeof(*hash_r));
 
        ctx->rec.ref_index = ctx->next_ref_index++;
 
@@ -486,7 +486,7 @@ mail_index_strmap_read_rec_next(struct mail_index_strmap_read_context *ctx,
                ctx->highest_str_idx = ctx->rec.str_idx;
 
        /* get to the next record */
-       ctx->data += sizeof(*crc32_r);
+       ctx->data += sizeof(*hash_r);
        ctx->str_idx_base += sizeof(ctx->rec.str_idx);
        return TRUE;
 }
@@ -547,12 +547,12 @@ strmap_read_block_init(struct mail_index_strmap_view *view,
 
 static int
 strmap_read_block_next(struct mail_index_strmap_read_context *ctx,
-                      uint32_t *crc32_r)
+                      uint32_t *hash_r)
 {
        uint32_t uid_diff;
        int ret;
 
-       if (mail_index_strmap_read_rec_next(ctx, crc32_r))
+       if (mail_index_strmap_read_rec_next(ctx, hash_r))
                return 1;
 
        /* get next UID */
@@ -565,7 +565,7 @@ strmap_read_block_next(struct mail_index_strmap_read_context *ctx,
                        return -1;
 
                ctx->rec.uid += uid_diff;
-               ret = mail_index_strmap_read_rec_first(ctx, crc32_r);
+               ret = mail_index_strmap_read_rec_first(ctx, hash_r);
        } while (ret == 0);
        return ret;
 }
@@ -635,12 +635,12 @@ strmap_view_sync_handle_conflict(struct mail_index_strmap_read_context *ctx,
 
 static int
 strmap_view_sync_block_check_conflicts(struct mail_index_strmap_read_context *ctx,
-                                      uint32_t crc32)
+                                      uint32_t hash)
 {
        struct mail_index_strmap_rec *hash_rec;
        struct hash2_iter iter;
 
-       if (crc32 == 0) {
+       if (hash == 0) {
                /* unique string - there are no conflicts */
                return 0;
        }
@@ -657,9 +657,9 @@ strmap_view_sync_block_check_conflicts(struct mail_index_strmap_read_context *ct
        strmap index until X has been expunged. */
        i_zero(&iter);
        while ((hash_rec = hash2_iterate(ctx->view->hash,
-                                        crc32, &iter)) != NULL &&
+                                        hash, &iter)) != NULL &&
               hash_rec->str_idx != ctx->rec.str_idx) {
-               /* CRC32 matches, but string index doesn't */
+               /* hash matches, but string index doesn't */
                if (!strmap_view_sync_handle_conflict(ctx, hash_rec, &iter)) {
                        ctx->lost_expunged_uid = hash_rec->uid;
                        return -1;
@@ -672,10 +672,10 @@ static int
 mail_index_strmap_view_sync_block(struct mail_index_strmap_read_context *ctx)
 {
        struct mail_index_strmap_rec *hash_rec;
-       uint32_t crc32, prev_uid = 0;
+       uint32_t hash, prev_uid = 0;
        int ret;
 
-       while ((ret = strmap_read_block_next(ctx, &crc32)) > 0) {
+       while ((ret = strmap_read_block_next(ctx, &hash)) > 0) {
                if (ctx->rec.uid <= ctx->view->last_added_uid) {
                        if (ctx->rec.uid < ctx->view->last_added_uid ||
                            prev_uid != ctx->rec.uid) {
@@ -685,7 +685,7 @@ mail_index_strmap_view_sync_block(struct mail_index_strmap_read_context *ctx)
                }
                prev_uid = ctx->rec.uid;
 
-               if (strmap_view_sync_block_check_conflicts(ctx, crc32) < 0) {
+               if (strmap_view_sync_block_check_conflicts(ctx, hash) < 0) {
                        ret = -1;
                        break;
                }
@@ -693,10 +693,10 @@ mail_index_strmap_view_sync_block(struct mail_index_strmap_read_context *ctx)
 
                /* add the record to records array */
                array_push_back(&ctx->view->recs, &ctx->rec);
-               array_push_back(&ctx->view->recs_crc32, &crc32);
+               array_push_back(&ctx->view->recs_hash, &hash);
 
                /* add a separate copy of the record to hash */
-               hash_rec = hash2_insert_hash(ctx->view->hash, crc32);
+               hash_rec = hash2_insert_hash(ctx->view->hash, hash);
                memcpy(hash_rec, &ctx->rec, sizeof(*hash_rec));
        }
        return strmap_read_block_deinit(ctx, ret, TRUE);
@@ -764,7 +764,7 @@ void mail_index_strmap_view_sync_add(struct mail_index_strmap_view_sync *sync,
                  ref_index > view->last_ref_index));
 
        hash_key.str = key;
-       hash_key.crc32 = crc32_str_nonzero(key);
+       hash_key.hash = crc32_str_nonzero(key);
 
        old_rec = hash2_lookup(view->hash, &hash_key);
        if (old_rec != NULL) {
@@ -781,7 +781,7 @@ void mail_index_strmap_view_sync_add(struct mail_index_strmap_view_sync *sync,
        rec->ref_index = ref_index;
        rec->str_idx = str_idx;
        array_push_back(&view->recs, rec);
-       array_push_back(&view->recs_crc32, &hash_key.crc32);
+       array_push_back(&view->recs_hash, &hash_key.hash);
 
        view->last_added_uid = uid;
        view->last_ref_index = ref_index;
@@ -802,7 +802,7 @@ void mail_index_strmap_view_sync_add_unique(struct mail_index_strmap_view_sync *
        rec.ref_index = ref_index;
        rec.str_idx = view->next_str_idx++;
        array_push_back(&view->recs, &rec);
-       array_append_zero(&view->recs_crc32);
+       array_append_zero(&view->recs_hash);
 
        view->last_added_uid = uid;
        view->last_ref_index = ref_index;
@@ -820,7 +820,7 @@ static void mail_index_strmap_view_renumber(struct mail_index_strmap_view *view)
 {
        struct mail_index_strmap_read_context ctx;
        struct mail_index_strmap_rec *recs, *hash_rec;
-       uint32_t prev_uid, str_idx, *recs_crc32, *renumber_map;
+       uint32_t prev_uid, str_idx, *recs_hash, *renumber_map;
        unsigned int i, dest, count, count2;
        int ret;
 
@@ -833,7 +833,7 @@ static void mail_index_strmap_view_renumber(struct mail_index_strmap_view *view)
        renumber_map = i_new(uint32_t, view->next_str_idx);
        str_idx = 0; prev_uid = 0;
        recs = array_get_modifiable(&view->recs, &count);
-       recs_crc32 = array_get_modifiable(&view->recs_crc32, &count2);
+       recs_hash = array_get_modifiable(&view->recs_hash, &count2);
        i_assert(count == count2);
 
        for (i = dest = 0; i < count; ) {
@@ -856,13 +856,13 @@ static void mail_index_strmap_view_renumber(struct mail_index_strmap_view *view)
                        renumber_map[recs[i].str_idx] = ++str_idx;
                if (i != dest) {
                        recs[dest] = recs[i];
-                       recs_crc32[dest] = recs_crc32[i];
+                       recs_hash[dest] = recs_hash[i];
                }
                i++; dest++;
        }
        i_assert(renumber_map[0] == 0);
        array_delete(&view->recs, dest, i-dest);
-       array_delete(&view->recs_crc32, dest, i-dest);
+       array_delete(&view->recs_hash, dest, i-dest);
        mail_index_strmap_zero_terminate(view);
 
        /* notify caller of the renumbering */
@@ -875,7 +875,7 @@ static void mail_index_strmap_view_renumber(struct mail_index_strmap_view *view)
        hash2_clear(view->hash);
        for (i = 0; i < count; i++) {
                recs[i].str_idx = renumber_map[recs[i].str_idx];
-               hash_rec = hash2_insert_hash(view->hash, recs_crc32[i]);
+               hash_rec = hash2_insert_hash(view->hash, recs_hash[i]);
                memcpy(hash_rec, &recs[i], sizeof(*hash_rec));
        }
 
@@ -889,7 +889,7 @@ static void mail_index_strmap_write_block(struct mail_index_strmap_view *view,
                                          unsigned int i, uint32_t base_uid)
 {
        const struct mail_index_strmap_rec *recs;
-       const uint32_t *crc32;
+       const uint32_t *hashes;
        unsigned int j, n, count, count2, uid_rec_count;
        uint32_t block_size;
        uint8_t *p, packed[MAIL_INDEX_PACK_MAX_SIZE*2];
@@ -902,7 +902,7 @@ static void mail_index_strmap_write_block(struct mail_index_strmap_view *view,
 
        /* write records */
        recs = array_get(&view->recs, &count);
-       crc32 = array_get(&view->recs_crc32, &count2);
+       hashes = array_get(&view->recs_hash, &count2);
        i_assert(count == count2);
        while (i < count) {
                /* @UNSAFE: <uid diff> */
@@ -919,7 +919,7 @@ static void mail_index_strmap_write_block(struct mail_index_strmap_view *view,
                }
                view->total_ref_count += uid_rec_count;
 
-               /* <n> <crc32>*count <str_idx>*count -
+               /* <n> <hash>*count <str_idx>*count -
                   FIXME: thread index specific code */
                i_assert(recs[i].ref_index == 0);
                if (uid_rec_count == 1) {
@@ -938,7 +938,7 @@ static void mail_index_strmap_write_block(struct mail_index_strmap_view *view,
                mail_index_pack_num(&p, n);
                o_stream_nsend(output, packed, p-packed);
                for (j = 0; j < uid_rec_count; j++)
-                       o_stream_nsend(output, &crc32[i+j], sizeof(crc32[i+j]));
+                       o_stream_nsend(output, &hashes[i+j], sizeof(hashes[i+j]));
                for (j = 0; j < uid_rec_count; j++) {
                        i_assert(j < 2 || recs[i+j].ref_index == j+1);
                        o_stream_nsend(output, &recs[i+j].str_idx,
@@ -1095,7 +1095,7 @@ mail_index_strmap_write_append(struct mail_index_strmap_view *view)
        const struct mail_index_strmap_rec *old_recs;
        unsigned int i, old_count;
        struct ostream *output;
-       uint32_t crc32, next_uid;
+       uint32_t hash, next_uid;
        bool full_block;
        int ret;
 
@@ -1134,7 +1134,7 @@ mail_index_strmap_write_append(struct mail_index_strmap_view *view)
        full_block = TRUE; ret = 0;
        while (i < old_count &&
               (ret = strmap_read_block_init(view, &ctx)) > 0) {
-               while ((ret = strmap_read_block_next(&ctx, &crc32)) > 0) {
+               while ((ret = strmap_read_block_next(&ctx, &hash)) > 0) {
                        if (ctx.rec.uid != old_recs[i].uid ||
                            ctx.rec.str_idx != old_recs[i].str_idx) {
                                /* mismatch */