Skip to content

Commit

Permalink
lib-index: Code cleanup - moved code to tview_lookup_ext_update()
Browse files Browse the repository at this point in the history
No functional changes.
  • Loading branch information
sirainen committed Feb 19, 2016
1 parent d09af09 commit ecb1ecd
Showing 1 changed file with 27 additions and 21 deletions.
48 changes: 27 additions & 21 deletions src/lib-index/mail-index-transaction-view.c
Expand Up @@ -321,16 +321,6 @@ static void tview_lookup_keywords(struct mail_index_view *view, uint32_t seq,
}
}

static struct mail_index_map *
tview_get_lookup_map(struct mail_index_view_transaction *tview)
{
if (tview->lookup_map == NULL) {
tview->lookup_map =
mail_index_map_clone(tview->view.index->map);
}
return tview->lookup_map;
}

static const void *
tview_return_updated_ext(struct mail_index_view_transaction *tview,
uint32_t seq, const void *data, uint32_t ext_id)
Expand Down Expand Up @@ -402,16 +392,39 @@ tview_is_ext_reset(struct mail_index_view_transaction *tview, uint32_t ext_id)
return ext_id < count && resets[ext_id].new_reset_id != 0;
}

static bool
tview_lookup_ext_update(struct mail_index_view_transaction *tview, uint32_t seq,
uint32_t ext_id, struct mail_index_map **map_r,
const void **data_r)
{
const ARRAY_TYPE(seq_array) *ext_buf;
const void *data;
unsigned int idx;
uint32_t map_ext_idx;

ext_buf = array_idx(&tview->t->ext_rec_updates, ext_id);
if (!array_is_created(ext_buf) ||
!mail_index_seq_array_lookup(ext_buf, seq, &idx))
return FALSE;

if (tview->lookup_map == NULL) {
tview->lookup_map =
mail_index_map_clone(tview->view.index->map);
}

data = array_idx(ext_buf, idx);
*map_r = tview->lookup_map;
*data_r = tview_return_updated_ext(tview, seq, data, ext_id);
return TRUE;
}

static void
tview_lookup_ext_full(struct mail_index_view *view, uint32_t seq,
uint32_t ext_id, struct mail_index_map **map_r,
const void **data_r, bool *expunged_r)
{
struct mail_index_view_transaction *tview =
(struct mail_index_view_transaction *)view;
const ARRAY_TYPE(seq_array) *ext_buf;
const void *data;
unsigned int idx;

i_assert(ext_id < array_count(&view->index->extensions));

Expand All @@ -422,15 +435,8 @@ tview_lookup_ext_full(struct mail_index_view *view, uint32_t seq,
ext_id < array_count(&tview->t->ext_rec_updates)) {
/* there are some ext updates in transaction.
see if there's any for this sequence. */
ext_buf = array_idx(&tview->t->ext_rec_updates, ext_id);
if (array_is_created(ext_buf) &&
mail_index_seq_array_lookup(ext_buf, seq, &idx)) {
data = array_idx(ext_buf, idx);
*map_r = tview_get_lookup_map(tview);
*data_r = tview_return_updated_ext(tview, seq, data,
ext_id);
if (tview_lookup_ext_update(tview, seq, ext_id, map_r, data_r))
return;
}
}

/* not updated, return the existing value, unless ext was
Expand Down

0 comments on commit ecb1ecd

Please sign in to comment.