You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucy.apache.org by nw...@apache.org on 2013/09/13 20:31:43 UTC
[lucy-commits] [11/17] git commit: refs/heads/cfish-string-prep1 - Convert
TextTermStepper to CharBuf
Convert TextTermStepper to CharBuf
Project: http://git-wip-us.apache.org/repos/asf/lucy/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucy/commit/56cbd56c
Tree: http://git-wip-us.apache.org/repos/asf/lucy/tree/56cbd56c
Diff: http://git-wip-us.apache.org/repos/asf/lucy/diff/56cbd56c
Branch: refs/heads/cfish-string-prep1
Commit: 56cbd56c139cd4dfed4bb56f726626ea1092697e
Parents: d575b0b
Author: Nick Wellnhofer <we...@aevum.de>
Authored: Tue Sep 10 01:17:42 2013 +0200
Committer: Nick Wellnhofer <we...@aevum.de>
Committed: Fri Sep 13 20:16:08 2013 +0200
----------------------------------------------------------------------
core/Lucy/Index/SegLexicon.c | 9 +----
core/Lucy/Plan/TextType.c | 78 +++++++++++++++++++++++++++------------
core/Lucy/Plan/TextType.cfh | 8 ++++
3 files changed, 65 insertions(+), 30 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/lucy/blob/56cbd56c/core/Lucy/Index/SegLexicon.c
----------------------------------------------------------------------
diff --git a/core/Lucy/Index/SegLexicon.c b/core/Lucy/Index/SegLexicon.c
index ab52dc2..19c6e7b 100644
--- a/core/Lucy/Index/SegLexicon.c
+++ b/core/Lucy/Index/SegLexicon.c
@@ -202,15 +202,10 @@ static void
S_scan_to(SegLexicon *self, Obj *target) {
SegLexiconIVARS *const ivars = SegLex_IVARS(self);
- // (mildly evil encapsulation violation, since value can be null)
- Obj *current = TermStepper_Get_Value(ivars->term_stepper);
- if (!Obj_Is_A(target, Obj_Get_VTable(current))) {
- THROW(ERR, "Target is a %o, and not comparable to a %o",
- Obj_Get_Class_Name(target), Obj_Get_Class_Name(current));
- }
-
// Keep looping until the term text is ge target.
do {
+ // (mildly evil encapsulation violation, since value can be null)
+ Obj *current = TermStepper_Get_Value(ivars->term_stepper);
const int32_t comparison = Obj_Compare_To(current, target);
if (comparison >= 0 && ivars->term_num != -1) { break; }
} while (SegLex_Next(self));
http://git-wip-us.apache.org/repos/asf/lucy/blob/56cbd56c/core/Lucy/Plan/TextType.c
----------------------------------------------------------------------
diff --git a/core/Lucy/Plan/TextType.c b/core/Lucy/Plan/TextType.c
index 40d0490..d4b6ae8 100644
--- a/core/Lucy/Plan/TextType.c
+++ b/core/Lucy/Plan/TextType.c
@@ -21,6 +21,7 @@
#include "Lucy/Plan/TextType.h"
#include "Lucy/Store/InStream.h"
#include "Lucy/Store/OutStream.h"
+#include "Clownfish/CharBuf.h"
#include "Clownfish/Util/StringHelper.h"
String*
@@ -54,22 +55,44 @@ TextTermStepper*
TextTermStepper_init(TextTermStepper *self) {
TermStepper_init((TermStepper*)self);
TextTermStepperIVARS *const ivars = TextTermStepper_IVARS(self);
- ivars->value = (Obj*)Str_new(0);
+ ivars->value = (Obj*)CB_new(0);
+ ivars->string = NULL;
return self;
}
void
+TextTermStepper_Destroy_IMP(TextTermStepper *self) {
+ TextTermStepperIVARS *const ivars = TextTermStepper_IVARS(self);
+ DECREF(ivars->string);
+ SUPER_DESTROY(self, TEXTTERMSTEPPER);
+}
+
+void
TextTermStepper_Set_Value_IMP(TextTermStepper *self, Obj *value) {
TextTermStepperIVARS *const ivars = TextTermStepper_IVARS(self);
CERTIFY(value, STRING);
- DECREF(ivars->value);
- ivars->value = INCREF(value);
+ Obj_Mimic(ivars->value, value);
+ // Invalidate string.
+ DECREF(ivars->string);
+ ivars->string = NULL;
+}
+
+Obj*
+TextTermStepper_Get_Value_IMP(TextTermStepper *self) {
+ TextTermStepperIVARS *const ivars = TextTermStepper_IVARS(self);
+ if (ivars->string == NULL) {
+ ivars->string = CB_To_String((CharBuf*)ivars->value);
+ }
+ return (Obj*)ivars->string;
}
void
TextTermStepper_Reset_IMP(TextTermStepper *self) {
TextTermStepperIVARS *const ivars = TextTermStepper_IVARS(self);
- Str_Set_Size((String*)ivars->value, 0);
+ CB_Set_Size((CharBuf*)ivars->value, 0);
+ // Invalidate string.
+ DECREF(ivars->string);
+ ivars->string = NULL;
}
void
@@ -81,18 +104,21 @@ TextTermStepper_Write_Key_Frame_IMP(TextTermStepper *self,
OutStream_Write_C32(outstream, size);
OutStream_Write_Bytes(outstream, buf, size);
Obj_Mimic(ivars->value, value);
+ // Invalidate string.
+ DECREF(ivars->string);
+ ivars->string = NULL;
}
void
TextTermStepper_Write_Delta_IMP(TextTermStepper *self, OutStream *outstream,
Obj *value) {
TextTermStepperIVARS *const ivars = TextTermStepper_IVARS(self);
- String *new_value = (String*)CERTIFY(value, STRING);
- String *last_value = (String*)ivars->value;
- char *new_text = (char*)Str_Get_Ptr8(new_value);
- size_t new_size = Str_Get_Size(new_value);
- char *last_text = (char*)Str_Get_Ptr8(last_value);
- size_t last_size = Str_Get_Size(last_value);
+ String *new_value = (String*)CERTIFY(value, STRING);
+ CharBuf *last_value = (CharBuf*)ivars->value;
+ char *new_text = (char*)Str_Get_Ptr8(new_value);
+ size_t new_size = Str_Get_Size(new_value);
+ char *last_text = (char*)CB_Get_Ptr8(last_value);
+ size_t last_size = CB_Get_Size(last_value);
// Count how many bytes the strings share at the top.
const int32_t overlap = StrHelp_overlap(last_text, new_text,
@@ -105,7 +131,11 @@ TextTermStepper_Write_Delta_IMP(TextTermStepper *self, OutStream *outstream,
OutStream_Write_String(outstream, diff_start_str, diff_len);
// Update value.
- Str_Mimic((String*)ivars->value, value);
+ Obj_Mimic(ivars->value, value);
+
+ // Invalidate string.
+ DECREF(ivars->string);
+ ivars->string = NULL;
}
void
@@ -115,15 +145,12 @@ TextTermStepper_Read_Key_Frame_IMP(TextTermStepper *self,
const uint32_t text_len = InStream_Read_C32(instream);
// Allocate space.
- if (ivars->value == NULL) {
- ivars->value = (Obj*)Str_new(text_len);
- }
- String *value = (String*)ivars->value;
- char *ptr = Str_Grow(value, text_len);
+ CharBuf *charbuf = (CharBuf*)ivars->value;
+ char *ptr = CB_Grow(charbuf, text_len);
// Set the value text.
InStream_Read_Bytes(instream, ptr, text_len);
- Str_Set_Size(value, text_len);
+ CB_Set_Size(charbuf, text_len);
if (!StrHelp_utf8_valid(ptr, text_len)) {
THROW(ERR, "Invalid UTF-8 sequence in '%o' at byte %i64",
InStream_Get_Filename(instream),
@@ -132,6 +159,10 @@ TextTermStepper_Read_Key_Frame_IMP(TextTermStepper *self,
// Null-terminate.
ptr[text_len] = '\0';
+
+ // Invalidate string.
+ DECREF(ivars->string);
+ ivars->string = NULL;
}
void
@@ -142,15 +173,12 @@ TextTermStepper_Read_Delta_IMP(TextTermStepper *self, InStream *instream) {
const uint32_t total_text_len = text_overlap + finish_chars_len;
// Allocate space.
- if (ivars->value == NULL) {
- ivars->value = (Obj*)Str_new(total_text_len);
- }
- String *value = (String*)ivars->value;
- char *ptr = Str_Grow(value, total_text_len);
+ CharBuf *charbuf = (CharBuf*)ivars->value;
+ char *ptr = CB_Grow(charbuf, total_text_len);
// Set the value text.
InStream_Read_Bytes(instream, ptr + text_overlap, finish_chars_len);
- Str_Set_Size(value, total_text_len);
+ CB_Set_Size(charbuf, 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),
@@ -159,6 +187,10 @@ TextTermStepper_Read_Delta_IMP(TextTermStepper *self, InStream *instream) {
// Null-terminate.
ptr[total_text_len] = '\0';
+
+ // Invalidate string.
+ DECREF(ivars->string);
+ ivars->string = NULL;
}
http://git-wip-us.apache.org/repos/asf/lucy/blob/56cbd56c/core/Lucy/Plan/TextType.cfh
----------------------------------------------------------------------
diff --git a/core/Lucy/Plan/TextType.cfh b/core/Lucy/Plan/TextType.cfh
index 0bcc3cc..654a06a 100644
--- a/core/Lucy/Plan/TextType.cfh
+++ b/core/Lucy/Plan/TextType.cfh
@@ -30,6 +30,8 @@ class Lucy::Plan::TextType inherits Lucy::Plan::FieldType {
class Lucy::Index::TermStepper::TextTermStepper
inherits Lucy::Index::TermStepper {
+ String *string;
+
inert incremented TextTermStepper*
new();
@@ -37,6 +39,9 @@ class Lucy::Index::TermStepper::TextTermStepper
init(TextTermStepper *self);
public void
+ Destroy(TextTermStepper *self);
+
+ public void
Reset(TextTermStepper *self);
/**
@@ -45,6 +50,9 @@ class Lucy::Index::TermStepper::TextTermStepper
public void
Set_Value(TextTermStepper *self, Obj *value = NULL);
+ public nullable Obj*
+ Get_Value(TextTermStepper *self);
+
public void
Write_Key_Frame(TextTermStepper *self, OutStream *outstream, Obj *value);