Skip to content

Commit

Permalink
global: Change calls to array_idx_modifiable to array_idx_get_space.
Browse files Browse the repository at this point in the history
Only calls that require space allocation are to be changed.
  • Loading branch information
Sergey-Kitov authored and sirainen committed Dec 15, 2017
1 parent 0fd9c89 commit 139143f
Show file tree
Hide file tree
Showing 11 changed files with 26 additions and 25 deletions.
2 changes: 1 addition & 1 deletion src/auth/main.c
Expand Up @@ -142,7 +142,7 @@ static void listeners_init(void)
int fd = MASTER_LISTEN_FD_FIRST + i;
struct auth_socket_listener *l;

l = array_idx_modifiable(&listeners, fd);
l = array_idx_get_space(&listeners, fd);
if (net_getunixname(fd, &path) < 0) {
if (errno != ENOTSOCK)
i_fatal("getunixname(%d) failed: %m", fd);
Expand Down
2 changes: 1 addition & 1 deletion src/lib-index/mail-cache-transaction.c
Expand Up @@ -363,7 +363,7 @@ mail_cache_link_records(struct mail_cache_transaction_ctx *ctx,
recs = array_get(&ctx->cache_data_seq, &seq_count);
rec = buffer_get_modifiable_data(ctx->cache_data, NULL);
for (i = 0; i < seq_count; i++) {
offsetp = array_idx_modifiable(&seq_offsets,
offsetp = array_idx_get_space(&seq_offsets,
recs[i].seq - ctx->min_seq);
if (*offsetp != 0)
prev_offset = *offsetp;
Expand Down
4 changes: 2 additions & 2 deletions src/lib-index/mail-index-modseq.c
Expand Up @@ -569,7 +569,7 @@ modseqs_update(ARRAY_TYPE(modseqs) *array, uint32_t seq1, uint32_t seq2,
uint64_t *modseqp;

for (; seq1 <= seq2; seq1++) {
modseqp = array_idx_modifiable(array, seq1-1);
modseqp = array_idx_get_space(array, seq1-1);
if (*modseqp < value)
*modseqp = value;
}
Expand All @@ -589,7 +589,7 @@ modseqs_idx_update(struct mail_index_modseq_sync *ctx, unsigned int idx,
}

modseq = mail_transaction_log_view_get_prev_modseq(ctx->log_view);
metadata = array_idx_modifiable(&ctx->mmap->metadata_modseqs, idx);
metadata = array_idx_get_space(&ctx->mmap->metadata_modseqs, idx);
if (!array_is_created(&metadata->modseqs))
i_array_init(&metadata->modseqs, seq2 + 16);
modseqs_update(&metadata->modseqs, seq1, seq2, modseq);
Expand Down
2 changes: 1 addition & 1 deletion src/lib-index/mail-index-sync-ext.c
Expand Up @@ -86,7 +86,7 @@ void mail_index_sync_init_handlers(struct mail_index_sync_map_ctx *ctx)
i_array_init(&ctx->extra_contexts, count);

/* make sure the extra_contexts contains everything */
(void)array_idx_modifiable(&ctx->extra_contexts, count - 1);
(void)array_idx_get_space(&ctx->extra_contexts, count - 1);
/* we need to update the expunge handler list in case they had
already been called */
ctx->expunge_handlers_set = FALSE;
Expand Down
12 changes: 6 additions & 6 deletions src/lib-index/mail-index-transaction-update.c
Expand Up @@ -959,7 +959,7 @@ void mail_index_ext_using_reset_id(struct mail_index_transaction *t,

if (!array_is_created(&t->ext_reset_ids))
i_array_init(&t->ext_reset_ids, ext_id + 2);
reset_id_p = array_idx_modifiable(&t->ext_reset_ids, ext_id);
reset_id_p = array_idx_get_space(&t->ext_reset_ids, ext_id);
changed = *reset_id_p != reset_id && *reset_id_p != 0;
*reset_id_p = reset_id;
if (changed) {
Expand Down Expand Up @@ -989,7 +989,7 @@ void mail_index_update_header_ext(struct mail_index_transaction *t,
if (!array_is_created(&t->ext_hdr_updates))
i_array_init(&t->ext_hdr_updates, ext_id + 2);

hdr = array_idx_modifiable(&t->ext_hdr_updates, ext_id);
hdr = array_idx_get_space(&t->ext_hdr_updates, ext_id);
if (hdr->alloc_size < offset || hdr->alloc_size - offset < size) {
i_assert(size < (size_t)-1 - offset);
new_size = nearest_power(offset + size);
Expand Down Expand Up @@ -1037,7 +1037,7 @@ void mail_index_update_ext(struct mail_index_transaction *t, uint32_t seq,

if (!array_is_created(&t->ext_rec_updates))
i_array_init(&t->ext_rec_updates, ext_id + 2);
array = array_idx_modifiable(&t->ext_rec_updates, ext_id);
array = array_idx_get_space(&t->ext_rec_updates, ext_id);

/* @UNSAFE */
if (!mail_index_seq_array_add(array, seq, data, record_size,
Expand Down Expand Up @@ -1066,7 +1066,7 @@ int mail_index_atomic_inc_ext(struct mail_index_transaction *t,
t->log_ext_updates = TRUE;
if (!array_is_created(&t->ext_rec_atomics))
i_array_init(&t->ext_rec_atomics, ext_id + 2);
array = array_idx_modifiable(&t->ext_rec_atomics, ext_id);
array = array_idx_get_space(&t->ext_rec_atomics, ext_id);
if (mail_index_seq_array_add(array, seq, &diff32, sizeof(diff32),
&old_diff32)) {
/* already incremented this sequence in this transaction */
Expand Down Expand Up @@ -1207,7 +1207,7 @@ void mail_index_update_keywords(struct mail_index_transaction *t, uint32_t seq,
first. */
if (remove_keywords != NULL) {
for (i = 0; i < remove_keywords->count; i++) {
u = array_idx_modifiable(&t->keyword_updates,
u = array_idx_get_space(&t->keyword_updates,
remove_keywords->idx[i]);
seq_range_array_remove(&u->add_seq, seq);
/* Don't bother updating remove_seq for new messages,
Expand All @@ -1220,7 +1220,7 @@ void mail_index_update_keywords(struct mail_index_transaction *t, uint32_t seq,
}
if (add_keywords != NULL) {
for (i = 0; i < add_keywords->count; i++) {
u = array_idx_modifiable(&t->keyword_updates,
u = array_idx_get_space(&t->keyword_updates,
add_keywords->idx[i]);
seq_range_array_add_with_init(&u->add_seq, 16, seq);
seq_range_array_remove(&u->remove_seq, seq);
Expand Down
4 changes: 2 additions & 2 deletions src/lib-storage/index/index-thread-finish.c
Expand Up @@ -259,7 +259,7 @@ static void thread_add_shadow_child(struct thread_finish_context *ctx,
{
struct mail_thread_shadow_node *parent_shadow, *child_shadow;

parent_shadow = array_idx_modifiable(&ctx->shadow_nodes, parent_idx);
parent_shadow = array_idx_get_space(&ctx->shadow_nodes, parent_idx);
child_shadow = array_idx_modifiable(&ctx->shadow_nodes, child_idx);

child_shadow->next_sibling_idx = parent_shadow->first_child_idx;
Expand Down Expand Up @@ -523,7 +523,7 @@ static void mail_thread_finish(struct thread_finish_context *ctx,
i_array_init(&ctx->roots, I_MIN(128, record_count));
i_array_init(&ctx->shadow_nodes, record_count);
/* make sure all shadow indexes are accessible directly. */
(void)array_idx_modifiable(&ctx->shadow_nodes, record_count);
(void)array_idx_get_space(&ctx->shadow_nodes, record_count);

mail_thread_create_shadows(ctx, record_count);

Expand Down
8 changes: 4 additions & 4 deletions src/lib-storage/index/index-thread-links.c
Expand Up @@ -14,7 +14,7 @@ static uint32_t thread_msg_add(struct mail_thread_cache *cache,
i_assert(msgid_idx != 0);
i_assert(msgid_idx < cache->first_invalid_msgid_str_idx);

node = array_idx_modifiable(&cache->thread_nodes, msgid_idx);
node = array_idx_get_space(&cache->thread_nodes, msgid_idx);
if (node->uid == 0)
node->uid = uid;
else {
Expand All @@ -23,7 +23,7 @@ static uint32_t thread_msg_add(struct mail_thread_cache *cache,
node->expunge_rebuilds = TRUE;

msgid_idx = cache->next_invalid_msgid_str_idx++;
node = array_idx_modifiable(&cache->thread_nodes, msgid_idx);
node = array_idx_get_space(&cache->thread_nodes, msgid_idx);
node->uid = uid;
}
return msgid_idx;
Expand Down Expand Up @@ -54,10 +54,10 @@ static void thread_link_reference(struct mail_thread_cache *cache,
grow. in such situation the other pointer may become invalid if
we don't get the pointers in correct order. */
if (child_idx < parent_idx) {
parent = array_idx_modifiable(&cache->thread_nodes, parent_idx);
parent = array_idx_get_space(&cache->thread_nodes, parent_idx);
child = array_idx_modifiable(&cache->thread_nodes, child_idx);
} else {
child = array_idx_modifiable(&cache->thread_nodes, child_idx);
child = array_idx_get_space(&cache->thread_nodes, child_idx);
parent = array_idx_modifiable(&cache->thread_nodes, parent_idx);
}

Expand Down
6 changes: 3 additions & 3 deletions src/lib-storage/index/maildir/maildir-keywords.c
Expand Up @@ -178,7 +178,7 @@ static int maildir_keywords_sync(struct maildir_keywords *mk)
new_name = p_strdup(mk->pool, p);
hash_table_insert(mk->hash, new_name, POINTER_CAST(idx + 1));

strp = array_idx_modifiable(&mk->list, idx);
strp = array_idx_get_space(&mk->list, idx);
*strp = new_name;
}
i_stream_destroy(&input);
Expand Down Expand Up @@ -229,7 +229,7 @@ maildir_keywords_create(struct maildir_keywords *mk, const char *name,
new_name = p_strdup(mk->pool, name);
hash_table_insert(mk->hash, new_name, POINTER_CAST(chridx + 1));

strp = array_idx_modifiable(&mk->list, chridx);
strp = array_idx_get_space(&mk->list, chridx);
*strp = new_name;

mk->changed = TRUE;
Expand Down Expand Up @@ -483,7 +483,7 @@ char maildir_keywords_idx_char(struct maildir_keywords_sync_ctx *ctx,
unsigned int chridx;
int ret;

chr_p = array_idx_modifiable(&ctx->idx_to_chr, idx);
chr_p = array_idx_get_space(&ctx->idx_to_chr, idx);
if (*chr_p != '\0')
return *chr_p;

Expand Down
2 changes: 1 addition & 1 deletion src/lib/hash2.c
Expand Up @@ -35,7 +35,7 @@ static void hash2_alloc_table(struct hash2_table *hash, unsigned int size)
hash->hash_table_size = size;

i_array_init(&hash->hash_table, hash->hash_table_size);
(void)array_idx_modifiable(&hash->hash_table, hash->hash_table_size-1);
(void)array_idx_get_space(&hash->hash_table, hash->hash_table_size-1);
}

struct hash2_table *
Expand Down
2 changes: 1 addition & 1 deletion src/lib/ioloop-epoll.c
Expand Up @@ -90,7 +90,7 @@ void io_loop_handle_add(struct io_file *io)
int op;
bool first;

list = array_idx_modifiable(&ctx->fd_index, io->fd);
list = array_idx_get_space(&ctx->fd_index, io->fd);
if (*list == NULL)
*list = i_new(struct io_list, 1);

Expand Down
7 changes: 4 additions & 3 deletions src/lib/module-context.h
Expand Up @@ -46,9 +46,10 @@
COMPILE_ERROR_IF_TYPES_NOT_COMPATIBLE(OBJ_REGISTER(obj), (id_ctx).reg)

#define MODULE_CONTEXT(obj, id_ctx) \
(*((void **)array_idx_modifiable(&(obj)->module_contexts, \
module_get_context_id(&(id_ctx).id)) + \
OBJ_REGISTER_COMPATIBLE(obj, id_ctx)))
(module_get_context_id(&(id_ctx).id) < array_count(&(obj)->module_contexts) ? \
(*((void **)array_idx_modifiable(&(obj)->module_contexts, \
module_get_context_id(&(id_ctx).id)) + \
OBJ_REGISTER_COMPATIBLE(obj, id_ctx))) : NULL)

#ifdef HAVE_TYPEOF
# define MODULE_CONTEXT_DEFINE(_name, _reg) \
Expand Down

0 comments on commit 139143f

Please sign in to comment.