Repository: lucy Updated Branches: refs/heads/master 123c48ea2 -> f5916a4e0
Prepare for BB_Mimic removal Replace BB_Mimic with BB_Grow/memcpy/BB_Set_Size. Project: http://git-wip-us.apache.org/repos/asf/lucy/repo Commit: http://git-wip-us.apache.org/repos/asf/lucy/commit/f5916a4e Tree: http://git-wip-us.apache.org/repos/asf/lucy/tree/f5916a4e Diff: http://git-wip-us.apache.org/repos/asf/lucy/diff/f5916a4e Branch: refs/heads/master Commit: f5916a4e0ddfcd5eef6fffd305e7cea37dd842d8 Parents: d59ed7b Author: Nick Wellnhofer <[email protected]> Authored: Wed Dec 9 15:45:22 2015 +0100 Committer: Nick Wellnhofer <[email protected]> Committed: Wed Dec 9 17:46:05 2015 +0100 ---------------------------------------------------------------------- core/Lucy/Index/PostingPool.c | 12 ++++++------ core/Lucy/Plan/TextType.c | 22 +++++++++++++++------- 2 files changed, 21 insertions(+), 13 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/lucy/blob/f5916a4e/core/Lucy/Index/PostingPool.c ---------------------------------------------------------------------- diff --git a/core/Lucy/Index/PostingPool.c b/core/Lucy/Index/PostingPool.c index 5404742..74714f3 100644 --- a/core/Lucy/Index/PostingPool.c +++ b/core/Lucy/Index/PostingPool.c @@ -355,8 +355,8 @@ S_write_terms_and_postings(PostingPool *self, PostingWriter *post_writer, RawPostingIVARS *post_ivars = RawPost_IVARS(posting); ByteBuf *last_term_text = BB_new_bytes(post_ivars->blob, post_ivars->content_len); - const char *last_text_buf = BB_Get_Buf(last_term_text); - uint32_t last_text_size = BB_Get_Size(last_term_text); + char *last_text_buf = BB_Get_Buf(last_term_text); + uint32_t last_text_size = BB_Get_Size(last_term_text); SkipStepper_Set_ID_And_Filepos(skip_stepper, 0, 0); // Initialize sentinel to be used on the last iter, using an empty string @@ -402,10 +402,10 @@ S_write_terms_and_postings(PostingPool *self, PostingWriter *post_writer, last_skip_filepos = tinfo_ivars->post_filepos; // Remember the term_text so we can write string diffs. - BB_Mimic_Bytes(last_term_text, post_ivars->blob, - post_ivars->content_len); - last_text_buf = BB_Get_Buf(last_term_text); - last_text_size = BB_Get_Size(last_term_text); + last_text_size = post_ivars->content_len; + last_text_buf = BB_Grow(last_term_text, last_text_size); + memcpy(last_text_buf, post_ivars->blob, last_text_size); + BB_Set_Size(last_term_text, last_text_size); } // Bail on last iter before writing invalid posting data. http://git-wip-us.apache.org/repos/asf/lucy/blob/f5916a4e/core/Lucy/Plan/TextType.c ---------------------------------------------------------------------- diff --git a/core/Lucy/Plan/TextType.c b/core/Lucy/Plan/TextType.c index be851ba..4737b8c 100644 --- a/core/Lucy/Plan/TextType.c +++ b/core/Lucy/Plan/TextType.c @@ -38,6 +38,10 @@ TextType_Primitive_ID_IMP(TextType *self) { /***************************************************************************/ +// The internal, current value of TextTermStepper is stored either as a +// String in `ivars->value` or, if `ivars->value == NULL`, as ByteBuf in +// `ivars->bytebuf`. + TextTermStepper* TextTermStepper_new() { TextTermStepper *self @@ -134,7 +138,9 @@ TextTermStepper_Write_Delta_IMP(TextTermStepper *self, OutStream *outstream, OutStream_Write_String(outstream, diff_start_str, diff_len); // Update value. - BB_Mimic_Bytes(ivars->bytebuf, new_text, new_size); + char *buf = BB_Grow(ivars->bytebuf, new_size); + memcpy(buf, new_text, new_size); + BB_Set_Size(ivars->bytebuf, new_size); // Invalidate string value. DECREF(ivars->value); @@ -172,10 +178,16 @@ TextTermStepper_Read_Delta_IMP(TextTermStepper *self, InStream *instream) { const uint32_t total_text_len = text_overlap + finish_chars_len; // Allocate space. + char *ptr = BB_Grow(ivars->bytebuf, total_text_len); + if (ivars->value) { - BB_Mimic(ivars->bytebuf, ivars->value); + // Copy overlapping part from string value. + memcpy(ptr, Str_Get_Ptr8((String*)ivars->value), text_overlap); + + // Invalidate string value. + DECREF(ivars->value); + ivars->value = NULL; } - char *ptr = BB_Grow(ivars->bytebuf, total_text_len); // Set the value text. InStream_Read_Bytes(instream, ptr + text_overlap, finish_chars_len); @@ -185,10 +197,6 @@ TextTermStepper_Read_Delta_IMP(TextTermStepper *self, InStream *instream) { InStream_Get_Filename(instream), InStream_Tell(instream) - finish_chars_len); } - - // Invalidate string value. - DECREF(ivars->value); - ivars->value = NULL; }
