Kouhei Sutou
null+****@clear*****
Mon Jan 16 15:53:39 JST 2017
Kouhei Sutou 2017-01-16 15:53:39 +0900 (Mon, 16 Jan 2017) New Revision: 9032492dd8204bb8e515b3b5bb4c2c355c234960 https://github.com/groonga/groonga/commit/9032492dd8204bb8e515b3b5bb4c2c355c234960 Message: ii: extract find segment code No logic change. Modified files: lib/ii.c Modified: lib/ii.c (+57 -37) =================================================================== --- lib/ii.c 2017-01-16 15:43:19 +0900 (e7e2fae) +++ lib/ii.c 2017-01-16 15:53:39 +0900 (fce61c6) @@ -3961,9 +3961,60 @@ buffer_split(grn_ctx *ctx, grn_ii *ii, uint32_t seg, grn_hash *h) #define SCALE_FACTOR 2048 #define MAX_NTERMS 8192 -#define SPLIT_COND (b->header.nterms > 1024 ||\ - (b->header.nterms > 1 &&\ - b->header.chunk_size * 100 > ii->header->total_chunk_size)) +#define SPLIT_COND(ii, buffer)\ + ((buffer)->header.nterms > 1024 ||\ + ((buffer)->header.nterms > 1 &&\ + (buffer)->header.chunk_size * 100 > (ii)->header->total_chunk_size)) + +inline static void +buffer_new_find_segment(grn_ctx *ctx, + grn_ii *ii, + int size, + grn_id tid, + grn_hash *h, + buffer **b, + uint32_t *lseg, + uint32_t *pseg) +{ + uint32_t *a; + + a = array_at(ctx, ii, tid); + if (!a) { + return; + } + + for (;;) { + uint32_t pos = a[0]; + if (!pos || (pos & 1)) { break; } + *pseg = buffer_open(ctx, ii, pos, NULL, b); + if (*pseg == NOT_ASSIGNED) { break; } + if ((*b)->header.buffer_free >= size + sizeof(buffer_term)) { + *lseg = LSEG(pos); + break; + } + buffer_close(ctx, ii, *pseg); + if (SPLIT_COND(ii, (*b))) { + /* ((S_SEGMENT - sizeof(buffer_header) + ii->header->bmax - + (*b)->header.nterms * sizeof(buffer_term)) * 4 < + (*b)->header.chunk_size) */ + GRN_LOG(ctx, GRN_LOG_DEBUG, + "nterms=%d chunk=%d total=%" GRN_FMT_INT64U, + (*b)->header.nterms, + (*b)->header.chunk_size, + ii->header->total_chunk_size >> 10); + if (buffer_split(ctx, ii, LSEG(pos), h)) { break; } + } else { + if (S_SEGMENT - sizeof(buffer_header) + - (*b)->header.nterms * sizeof(buffer_term) + < size + sizeof(buffer_term)) { + break; + } + if (buffer_flush(ctx, ii, LSEG(pos), h)) { break; } + } + } + + array_unref(ii, tid); +} inline static uint32_t buffer_new(grn_ctx *ctx, grn_ii *ii, int size, uint32_t *pos, @@ -3972,7 +4023,7 @@ buffer_new(grn_ctx *ctx, grn_ii *ii, int size, uint32_t *pos, buffer *b = NULL; grn_id tid; uint16_t offset; - uint32_t *a, lseg = NOT_ASSIGNED, pseg = NOT_ASSIGNED; + uint32_t lseg = NOT_ASSIGNED, pseg = NOT_ASSIGNED; grn_table_cursor *tc = NULL; if (S_SEGMENT - sizeof(buffer_header) < size + sizeof(buffer_term)) { DEFINE_NAME(ii); @@ -4003,38 +4054,7 @@ buffer_new(grn_ctx *ctx, grn_ii *ii, int size, uint32_t *pos, while (ctx->rc == GRN_SUCCESS && lseg == NOT_ASSIGNED && (tid = grn_table_cursor_next(ctx, tc))) { - if ((a = array_at(ctx, ii, tid))) { - for (;;) { - uint32_t pos = a[0]; - if (!pos || (pos & 1)) { break; } - pseg = buffer_open(ctx, ii, pos, NULL, &b); - if (pseg == NOT_ASSIGNED) { break; } - if (b->header.buffer_free >= size + sizeof(buffer_term)) { - lseg = LSEG(pos); - break; - } - buffer_close(ctx, ii, pseg); - if (SPLIT_COND) { - /* ((S_SEGMENT - sizeof(buffer_header) + ii->header->bmax - - b->header.nterms * sizeof(buffer_term)) * 4 < - b->header.chunk_size) */ - GRN_LOG(ctx, GRN_LOG_DEBUG, - "nterms=%d chunk=%d total=%" GRN_FMT_INT64U, - b->header.nterms, - b->header.chunk_size, - ii->header->total_chunk_size >> 10); - if (buffer_split(ctx, ii, LSEG(pos), h)) { break; } - } else { - if (S_SEGMENT - sizeof(buffer_header) - - b->header.nterms * sizeof(buffer_term) - < size + sizeof(buffer_term)) { - break; - } - if (buffer_flush(ctx, ii, LSEG(pos), h)) { break; } - } - } - array_unref(ii, tid); - } + buffer_new_find_segment(ctx, ii, size, tid, h, &b, &lseg, &pseg); } grn_table_cursor_close(ctx, tc); } @@ -4402,7 +4422,7 @@ grn_ii_update_one(grn_ctx *ctx, grn_ii *ii, grn_id tid, grn_ii_updspec *u, grn_h GRN_LOG(ctx, GRN_LOG_DEBUG, "flushing a[0]=%d seg=%d(%p) free=%d", a[0], LSEG(a[0]), b, b->header.buffer_free); buffer_close(ctx, ii, pseg); - if (SPLIT_COND) { + if (SPLIT_COND(ii, b)) { /*((S_SEGMENT - sizeof(buffer_header) + ii->header->bmax - b->header.nterms * sizeof(buffer_term)) * 4 < b->header.chunk_size)*/ -------------- next part -------------- HTML����������������������������...Download