Switch PostingPool and TextTermStepper over to ByteBufs
Project: http://git-wip-us.apache.org/repos/asf/lucy/repo Commit: http://git-wip-us.apache.org/repos/asf/lucy/commit/85204c5a Tree: http://git-wip-us.apache.org/repos/asf/lucy/tree/85204c5a Diff: http://git-wip-us.apache.org/repos/asf/lucy/diff/85204c5a Branch: refs/heads/master Commit: 85204c5a20efd96ef21773c02c13769eb084a6b1 Parents: d6fdddb Author: Nick Wellnhofer <wellnho...@aevum.de> Authored: Tue Nov 10 13:27:21 2015 +0100 Committer: Nick Wellnhofer <wellnho...@aevum.de> Committed: Sun Nov 15 12:38:47 2015 +0100 ---------------------------------------------------------------------- core/Lucy/Index/PostingPool.c | 18 +++++++++--------- core/Lucy/Plan/TextType.c | 38 ++++++++++++++++---------------------- core/Lucy/Plan/TextType.cfh | 2 +- 3 files changed, 26 insertions(+), 32 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/lucy/blob/85204c5a/core/Lucy/Index/PostingPool.c ---------------------------------------------------------------------- diff --git a/core/Lucy/Index/PostingPool.c b/core/Lucy/Index/PostingPool.c index 4ef1c3e..5404742 100644 --- a/core/Lucy/Index/PostingPool.c +++ b/core/Lucy/Index/PostingPool.c @@ -22,7 +22,7 @@ #include "Lucy/Util/ToolSet.h" #include "Lucy/Index/PostingPool.h" -#include "Clownfish/CharBuf.h" +#include "Clownfish/ByteBuf.h" #include "Lucy/Analysis/Inversion.h" #include "Lucy/Plan/Architecture.h" #include "Lucy/Plan/FieldType.h" @@ -353,10 +353,10 @@ S_write_terms_and_postings(PostingPool *self, PostingWriter *post_writer, RawPosting *posting = (RawPosting*)CERTIFY(PostPool_Fetch(self), RAWPOSTING); RawPostingIVARS *post_ivars = RawPost_IVARS(posting); - CharBuf *last_term_text - = CB_new_from_trusted_utf8(post_ivars->blob, post_ivars->content_len); - const char *last_text_buf = CB_Get_Ptr8(last_term_text); - uint32_t last_text_size = CB_Get_Size(last_term_text); + 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); 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. - CB_Mimic_Utf8(last_term_text, post_ivars->blob, - post_ivars->content_len); - last_text_buf = CB_Get_Ptr8(last_term_text); - last_text_size = CB_Get_Size(last_term_text); + 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); } // Bail on last iter before writing invalid posting data. http://git-wip-us.apache.org/repos/asf/lucy/blob/85204c5a/core/Lucy/Plan/TextType.c ---------------------------------------------------------------------- diff --git a/core/Lucy/Plan/TextType.c b/core/Lucy/Plan/TextType.c index a9f66b2..be851ba 100644 --- a/core/Lucy/Plan/TextType.c +++ b/core/Lucy/Plan/TextType.c @@ -21,7 +21,7 @@ #include "Lucy/Plan/TextType.h" #include "Lucy/Store/InStream.h" #include "Lucy/Store/OutStream.h" -#include "Clownfish/CharBuf.h" +#include "Clownfish/ByteBuf.h" #include "Clownfish/Util/StringHelper.h" TermStepper* @@ -49,14 +49,14 @@ TextTermStepper* TextTermStepper_init(TextTermStepper *self) { TermStepper_init((TermStepper*)self); TextTermStepperIVARS *const ivars = TextTermStepper_IVARS(self); - ivars->charbuf = CB_new(0); + ivars->bytebuf = BB_new(0); return self; } void TextTermStepper_Destroy_IMP(TextTermStepper *self) { TextTermStepperIVARS *const ivars = TextTermStepper_IVARS(self); - DECREF(ivars->charbuf); + DECREF(ivars->bytebuf); SUPER_DESTROY(self, TEXTTERMSTEPPER); } @@ -78,7 +78,7 @@ Obj* TextTermStepper_Get_Value_IMP(TextTermStepper *self) { TextTermStepperIVARS *const ivars = TextTermStepper_IVARS(self); if (ivars->value == NULL) { - ivars->value = (Obj*)CB_To_String(ivars->charbuf); + ivars->value = (Obj*)BB_Trusted_Utf8_To_String(ivars->bytebuf); } return ivars->value; } @@ -88,7 +88,7 @@ TextTermStepper_Reset_IMP(TextTermStepper *self) { TextTermStepperIVARS *const ivars = TextTermStepper_IVARS(self); DECREF(ivars->value); ivars->value = NULL; - CB_Set_Size(ivars->charbuf, 0); + BB_Set_Size(ivars->bytebuf, 0); } void @@ -107,9 +107,9 @@ void TextTermStepper_Write_Delta_IMP(TextTermStepper *self, OutStream *outstream, Obj *value) { TextTermStepperIVARS *const ivars = TextTermStepper_IVARS(self); - CharBuf *charbuf = (CharBuf*)CERTIFY(value, CHARBUF); - const char *new_text = CB_Get_Ptr8(charbuf); - size_t new_size = CB_Get_Size(charbuf); + ByteBuf *bytebuf = (ByteBuf*)CERTIFY(value, BYTEBUF); + const char *new_text = BB_Get_Buf(bytebuf); + size_t new_size = BB_Get_Size(bytebuf); const char *last_text; size_t last_size; @@ -119,8 +119,8 @@ TextTermStepper_Write_Delta_IMP(TextTermStepper *self, OutStream *outstream, last_size = Str_Get_Size(last_string); } else { - last_text = CB_Get_Ptr8(ivars->charbuf); - last_size = CB_Get_Size(ivars->charbuf); + last_text = BB_Get_Buf(ivars->bytebuf); + last_size = BB_Get_Size(ivars->bytebuf); } // Count how many bytes the strings share at the top. @@ -134,7 +134,7 @@ TextTermStepper_Write_Delta_IMP(TextTermStepper *self, OutStream *outstream, OutStream_Write_String(outstream, diff_start_str, diff_len); // Update value. - CB_Mimic_Utf8(ivars->charbuf, new_text, new_size); + BB_Mimic_Bytes(ivars->bytebuf, new_text, new_size); // Invalidate string value. DECREF(ivars->value); @@ -148,20 +148,17 @@ TextTermStepper_Read_Key_Frame_IMP(TextTermStepper *self, const uint32_t text_len = InStream_Read_C32(instream); // Allocate space. - char *ptr = CB_Grow(ivars->charbuf, text_len); + char *ptr = BB_Grow(ivars->bytebuf, text_len); // Set the value text. InStream_Read_Bytes(instream, ptr, text_len); - CB_Set_Size(ivars->charbuf, text_len); + BB_Set_Size(ivars->bytebuf, text_len); if (!StrHelp_utf8_valid(ptr, text_len)) { THROW(ERR, "Invalid UTF-8 sequence in '%o' at byte %i64", InStream_Get_Filename(instream), InStream_Tell(instream) - text_len); } - // Null-terminate. - ptr[text_len] = '\0'; - // Invalidate string value. DECREF(ivars->value); ivars->value = NULL; @@ -176,22 +173,19 @@ TextTermStepper_Read_Delta_IMP(TextTermStepper *self, InStream *instream) { // Allocate space. if (ivars->value) { - CB_Mimic(ivars->charbuf, ivars->value); + BB_Mimic(ivars->bytebuf, ivars->value); } - char *ptr = CB_Grow(ivars->charbuf, total_text_len); + char *ptr = BB_Grow(ivars->bytebuf, total_text_len); // Set the value text. InStream_Read_Bytes(instream, ptr + text_overlap, finish_chars_len); - CB_Set_Size(ivars->charbuf, total_text_len); + BB_Set_Size(ivars->bytebuf, total_text_len); if (!StrHelp_utf8_valid(ptr, total_text_len)) { THROW(ERR, "Invalid UTF-8 sequence in '%o' at byte %i64", InStream_Get_Filename(instream), InStream_Tell(instream) - finish_chars_len); } - // Null-terminate. - ptr[total_text_len] = '\0'; - // Invalidate string value. DECREF(ivars->value); ivars->value = NULL; http://git-wip-us.apache.org/repos/asf/lucy/blob/85204c5a/core/Lucy/Plan/TextType.cfh ---------------------------------------------------------------------- diff --git a/core/Lucy/Plan/TextType.cfh b/core/Lucy/Plan/TextType.cfh index 934529c..87bd125 100644 --- a/core/Lucy/Plan/TextType.cfh +++ b/core/Lucy/Plan/TextType.cfh @@ -27,7 +27,7 @@ class Lucy::Plan::TextType inherits Lucy::Plan::FieldType { class Lucy::Index::TermStepper::TextTermStepper inherits Lucy::Index::TermStepper { - CharBuf *charbuf; + ByteBuf *bytebuf; inert incremented TextTermStepper* new();