You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucy.apache.org by ma...@apache.org on 2013/06/03 03:44:02 UTC

[lucy-commits] [06/13] git commit: refs/heads/lucify-serialization - Use Freezer for CharBuf serialization.

Use Freezer for CharBuf serialization.

Swap out CharBuf serialization methods for Freezer-based routines.


Project: http://git-wip-us.apache.org/repos/asf/lucy/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucy/commit/44d00c35
Tree: http://git-wip-us.apache.org/repos/asf/lucy/tree/44d00c35
Diff: http://git-wip-us.apache.org/repos/asf/lucy/diff/44d00c35

Branch: refs/heads/lucify-serialization
Commit: 44d00c357c6eb0181b9a9a7ea52e531c8e516662
Parents: 2de7994
Author: Marvin Humphrey <ma...@rectangular.com>
Authored: Fri May 31 12:27:08 2013 -0700
Committer: Marvin Humphrey <ma...@rectangular.com>
Committed: Sat Jun 1 19:10:34 2013 -0700

----------------------------------------------------------------------
 clownfish/runtime/core/Clownfish/CharBuf.c   |    5 +++++
 clownfish/runtime/core/Clownfish/CharBuf.cfh |    7 +++++++
 core/Clownfish/Hash.c                        |    2 +-
 core/Lucy/Index/DocWriter.c                  |    3 ++-
 core/Lucy/Index/HighlightReader.c            |    4 ++--
 core/Lucy/Index/HighlightWriter.c            |    3 ++-
 core/Lucy/Index/Similarity.c                 |    6 +++---
 core/Lucy/Index/TermVector.c                 |   11 +++++------
 core/Lucy/Search/LeafQuery.c                 |   10 +++++-----
 core/Lucy/Search/PhraseQuery.c               |    5 ++---
 core/Lucy/Search/PolyQuery.c                 |    5 ++---
 core/Lucy/Search/RangeQuery.c                |    5 ++---
 core/Lucy/Search/SortRule.c                  |    6 +++---
 core/Lucy/Search/TermQuery.c                 |    5 ++---
 core/LucyX/Search/ProximityQuery.c           |    5 ++---
 15 files changed, 45 insertions(+), 37 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucy/blob/44d00c35/clownfish/runtime/core/Clownfish/CharBuf.c
----------------------------------------------------------------------
diff --git a/clownfish/runtime/core/Clownfish/CharBuf.c b/clownfish/runtime/core/Clownfish/CharBuf.c
index 9953dc6..d21cf9a 100644
--- a/clownfish/runtime/core/Clownfish/CharBuf.c
+++ b/clownfish/runtime/core/Clownfish/CharBuf.c
@@ -96,6 +96,11 @@ CB_new_from_trusted_utf8(const char *ptr, size_t size) {
 CharBuf*
 CB_new_steal_from_trusted_str(char *ptr, size_t size, size_t cap) {
     CharBuf *self = (CharBuf*)VTable_Make_Obj(CHARBUF);
+    return CB_init_steal_trusted_str(self, ptr, size, cap);
+}
+
+CharBuf*
+CB_init_steal_trusted_str(CharBuf *self, char *ptr, size_t size, size_t cap) {
     self->ptr  = ptr;
     self->size = size;
     self->cap  = cap;

http://git-wip-us.apache.org/repos/asf/lucy/blob/44d00c35/clownfish/runtime/core/Clownfish/CharBuf.cfh
----------------------------------------------------------------------
diff --git a/clownfish/runtime/core/Clownfish/CharBuf.cfh b/clownfish/runtime/core/Clownfish/CharBuf.cfh
index 257f038..987eb67 100644
--- a/clownfish/runtime/core/Clownfish/CharBuf.cfh
+++ b/clownfish/runtime/core/Clownfish/CharBuf.cfh
@@ -57,6 +57,13 @@ class Clownfish::CharBuf cnick CB
     inert incremented CharBuf*
     new_steal_from_trusted_str(char *ptr, size_t size, size_t cap);
 
+    /** Initialize the CharBuf using the passed-in string.  Do not check
+     * validity of supplied UTF-8.
+     */
+    public inert CharBuf*
+    init_steal_trusted_str(decremented CharBuf *self, char *ptr,
+                           size_t size, size_t cap);
+
     /** Return a pointer to a new CharBuf which contains formatted data
      * expanded according to CB_VCatF.
      *

http://git-wip-us.apache.org/repos/asf/lucy/blob/44d00c35/core/Clownfish/Hash.c
----------------------------------------------------------------------
diff --git a/core/Clownfish/Hash.c b/core/Clownfish/Hash.c
index 40c9a0b..949d836 100644
--- a/core/Clownfish/Hash.c
+++ b/core/Clownfish/Hash.c
@@ -186,7 +186,7 @@ Hash_serialize(Hash *self, OutStream *outstream) {
     Hash_Iterate(self);
     while (Hash_Next(self, &key, &val)) {
         if (Obj_Is_A(key, CHARBUF)) {
-            Obj_Serialize(key, outstream);
+            Freezer_serialize_charbuf((CharBuf*)key, outstream);
             FREEZE(val, outstream);
         }
     }

http://git-wip-us.apache.org/repos/asf/lucy/blob/44d00c35/core/Lucy/Index/DocWriter.c
----------------------------------------------------------------------
diff --git a/core/Lucy/Index/DocWriter.c b/core/Lucy/Index/DocWriter.c
index 1844849..06355f0 100644
--- a/core/Lucy/Index/DocWriter.c
+++ b/core/Lucy/Index/DocWriter.c
@@ -29,6 +29,7 @@
 #include "Lucy/Plan/Schema.h"
 #include "Lucy/Store/Folder.h"
 #include "Lucy/Store/OutStream.h"
+#include "Lucy/Util/Freezer.h"
 
 static OutStream*
 S_lazy_init(DocWriter *self);
@@ -108,7 +109,7 @@ DocWriter_add_inverted_doc(DocWriter *self, Inverter *inverter,
         if (FType_Stored(type)) {
             CharBuf *field = Inverter_Get_Field_Name(inverter);
             Obj *value = Inverter_Get_Value(inverter);
-            CB_Serialize(field, dat_out);
+            Freezer_serialize_charbuf(field, dat_out);
             switch (FType_Primitive_ID(type) & FType_PRIMITIVE_ID_MASK) {
                 case FType_TEXT: {
                     uint8_t *buf  = CB_Get_Ptr8((CharBuf*)value);

http://git-wip-us.apache.org/repos/asf/lucy/blob/44d00c35/core/Lucy/Index/HighlightReader.c
----------------------------------------------------------------------
diff --git a/core/Lucy/Index/HighlightReader.c b/core/Lucy/Index/HighlightReader.c
index 97c3657..405107e 100644
--- a/core/Lucy/Index/HighlightReader.c
+++ b/core/Lucy/Index/HighlightReader.c
@@ -29,6 +29,7 @@
 #include "Lucy/Store/InStream.h"
 #include "Lucy/Store/OutStream.h"
 #include "Lucy/Store/Folder.h"
+#include "Lucy/Util/Freezer.h"
 
 HighlightReader*
 HLReader_init(HighlightReader *self, Schema *schema, Folder *folder,
@@ -191,8 +192,7 @@ DefHLReader_fetch_doc_vec(DefaultHighlightReader *self, int32_t doc_id) {
 
     uint32_t num_fields = InStream_Read_C32(dat_in);
     while (num_fields--) {
-        CharBuf *field
-            = CB_Deserialize((CharBuf*)VTable_Make_Obj(CHARBUF), dat_in);
+        CharBuf *field = Freezer_read_charbuf(dat_in);
         ByteBuf *field_buf
             = BB_Deserialize((ByteBuf*)VTable_Make_Obj(BYTEBUF), dat_in);
         DocVec_Add_Field_Buf(doc_vec, field, field_buf);

http://git-wip-us.apache.org/repos/asf/lucy/blob/44d00c35/core/Lucy/Index/HighlightWriter.c
----------------------------------------------------------------------
diff --git a/core/Lucy/Index/HighlightWriter.c b/core/Lucy/Index/HighlightWriter.c
index b9c3267..98bc1f2 100644
--- a/core/Lucy/Index/HighlightWriter.c
+++ b/core/Lucy/Index/HighlightWriter.c
@@ -36,6 +36,7 @@
 #include "Lucy/Store/Folder.h"
 #include "Lucy/Store/OutStream.h"
 #include "Lucy/Store/InStream.h"
+#include "Lucy/Util/Freezer.h"
 
 static OutStream*
 S_lazy_init(HighlightWriter *self);
@@ -127,7 +128,7 @@ HLWriter_add_inverted_doc(HighlightWriter *self, Inverter *inverter,
             CharBuf   *field     = Inverter_Get_Field_Name(inverter);
             Inversion *inversion = Inverter_Get_Inversion(inverter);
             ByteBuf   *tv_buf    = HLWriter_TV_Buf(self, inversion);
-            CB_Serialize(field, dat_out);
+            Freezer_serialize_charbuf(field, dat_out);
             BB_Serialize(tv_buf, dat_out);
             DECREF(tv_buf);
         }

http://git-wip-us.apache.org/repos/asf/lucy/blob/44d00c35/core/Lucy/Index/Similarity.c
----------------------------------------------------------------------
diff --git a/core/Lucy/Index/Similarity.c b/core/Lucy/Index/Similarity.c
index 3e4b9a3..2118cdc 100644
--- a/core/Lucy/Index/Similarity.c
+++ b/core/Lucy/Index/Similarity.c
@@ -29,6 +29,7 @@
 #include "Lucy/Plan/Schema.h"
 #include "Lucy/Store/InStream.h"
 #include "Lucy/Store/OutStream.h"
+#include "Lucy/Util/Freezer.h"
 
 Similarity*
 Sim_new() {
@@ -98,13 +99,12 @@ Sim_load(Similarity *self, Obj *dump) {
 void
 Sim_serialize(Similarity *self, OutStream *target) {
     // Only the class name.
-    CB_Serialize(Sim_Get_Class_Name(self), target);
+    Freezer_serialize_charbuf(Sim_Get_Class_Name(self), target);
 }
 
 Similarity*
 Sim_deserialize(Similarity *self, InStream *instream) {
-    CharBuf *class_name
-        = CB_Deserialize((CharBuf*)VTable_Make_Obj(CHARBUF), instream);
+    CharBuf *class_name = Freezer_read_charbuf(instream);
     if (!CB_Equals(class_name, (Obj*)Sim_Get_Class_Name(self))) {
         THROW(ERR, "Class name mismatch: '%o' '%o'", Sim_Get_Class_Name(self),
               class_name);

http://git-wip-us.apache.org/repos/asf/lucy/blob/44d00c35/core/Lucy/Index/TermVector.c
----------------------------------------------------------------------
diff --git a/core/Lucy/Index/TermVector.c b/core/Lucy/Index/TermVector.c
index 9859fff..4c3216b 100644
--- a/core/Lucy/Index/TermVector.c
+++ b/core/Lucy/Index/TermVector.c
@@ -21,6 +21,7 @@
 #include "Lucy/Index/TermVector.h"
 #include "Lucy/Store/InStream.h"
 #include "Lucy/Store/OutStream.h"
+#include "Lucy/Util/Freezer.h"
 
 TermVector*
 TV_new(const CharBuf *field, const CharBuf *text, I32Array *positions,
@@ -81,8 +82,8 @@ TV_serialize(TermVector *self, OutStream *target) {
     int32_t *starts = self->start_offsets->ints;
     int32_t *ends   = self->start_offsets->ints;
 
-    CB_Serialize(self->field, target);
-    CB_Serialize(self->text, target);
+    Freezer_serialize_charbuf(self->field, target);
+    Freezer_serialize_charbuf(self->text, target);
     OutStream_Write_C32(target, self->num_pos);
 
     for (uint32_t i = 0; i < self->num_pos; i++) {
@@ -94,10 +95,8 @@ TV_serialize(TermVector *self, OutStream *target) {
 
 TermVector*
 TV_deserialize(TermVector *self, InStream *instream) {
-    CharBuf *field
-        = CB_Deserialize((CharBuf*)VTable_Make_Obj(CHARBUF), instream);
-    CharBuf *text
-        = CB_Deserialize((CharBuf*)VTable_Make_Obj(CHARBUF), instream);
+    CharBuf *field = Freezer_read_charbuf(instream);
+    CharBuf *text  = Freezer_read_charbuf(instream);
     uint32_t num_pos = InStream_Read_C32(instream);
 
     // Read positional data.

http://git-wip-us.apache.org/repos/asf/lucy/blob/44d00c35/core/Lucy/Search/LeafQuery.c
----------------------------------------------------------------------
diff --git a/core/Lucy/Search/LeafQuery.c b/core/Lucy/Search/LeafQuery.c
index 781eb11..7dc6864 100644
--- a/core/Lucy/Search/LeafQuery.c
+++ b/core/Lucy/Search/LeafQuery.c
@@ -22,6 +22,7 @@
 #include "Lucy/Search/Searcher.h"
 #include "Lucy/Store/InStream.h"
 #include "Lucy/Store/OutStream.h"
+#include "Lucy/Util/Freezer.h"
 
 LeafQuery*
 LeafQuery_new(const CharBuf *field, const CharBuf *text) {
@@ -82,25 +83,24 @@ void
 LeafQuery_serialize(LeafQuery *self, OutStream *outstream) {
     if (self->field) {
         OutStream_Write_U8(outstream, true);
-        CB_Serialize(self->field, outstream);
+        Freezer_serialize_charbuf(self->field, outstream);
     }
     else {
         OutStream_Write_U8(outstream, false);
     }
-    CB_Serialize(self->text, outstream);
+    Freezer_serialize_charbuf(self->text, outstream);
     OutStream_Write_F32(outstream, self->boost);
 }
 
 LeafQuery*
 LeafQuery_deserialize(LeafQuery *self, InStream *instream) {
     if (InStream_Read_U8(instream)) {
-        self->field
-            = CB_Deserialize((CharBuf*)VTable_Make_Obj(CHARBUF), instream);
+        self->field = Freezer_read_charbuf(instream);
     }
     else {
         self->field = NULL;
     }
-    self->text = CB_Deserialize((CharBuf*)VTable_Make_Obj(CHARBUF), instream);
+    self->text = Freezer_read_charbuf(instream);
     self->boost = InStream_Read_F32(instream);
     return self;
 }

http://git-wip-us.apache.org/repos/asf/lucy/blob/44d00c35/core/Lucy/Search/PhraseQuery.c
----------------------------------------------------------------------
diff --git a/core/Lucy/Search/PhraseQuery.c b/core/Lucy/Search/PhraseQuery.c
index 38005ea..9fd7046 100644
--- a/core/Lucy/Search/PhraseQuery.c
+++ b/core/Lucy/Search/PhraseQuery.c
@@ -75,15 +75,14 @@ S_do_init(PhraseQuery *self, CharBuf *field, VArray *terms, float boost) {
 void
 PhraseQuery_serialize(PhraseQuery *self, OutStream *outstream) {
     OutStream_Write_F32(outstream, self->boost);
-    CB_Serialize(self->field, outstream);
+    Freezer_serialize_charbuf(self->field, outstream);
     VA_Serialize(self->terms, outstream);
 }
 
 PhraseQuery*
 PhraseQuery_deserialize(PhraseQuery *self, InStream *instream) {
     float boost = InStream_Read_F32(instream);
-    CharBuf *field
-        = CB_Deserialize((CharBuf*)VTable_Make_Obj(CHARBUF), instream);
+    CharBuf *field = Freezer_read_charbuf(instream);
     VArray *terms
         = VA_Deserialize((VArray*)VTable_Make_Obj(VARRAY), instream);
     return S_do_init(self, field, terms, boost);

http://git-wip-us.apache.org/repos/asf/lucy/blob/44d00c35/core/Lucy/Search/PolyQuery.c
----------------------------------------------------------------------
diff --git a/core/Lucy/Search/PolyQuery.c b/core/Lucy/Search/PolyQuery.c
index 8ad4862..bece9ea 100644
--- a/core/Lucy/Search/PolyQuery.c
+++ b/core/Lucy/Search/PolyQuery.c
@@ -167,7 +167,7 @@ PolyCompiler_highlight_spans(PolyCompiler *self, Searcher *searcher,
 
 void
 PolyCompiler_serialize(PolyCompiler *self, OutStream *outstream) {
-    CB_Serialize(PolyCompiler_Get_Class_Name(self), outstream);
+    Freezer_serialize_charbuf(PolyCompiler_Get_Class_Name(self), outstream);
     VA_Serialize(self->children, outstream);
     PolyCompiler_Serialize_t super_serialize
         = SUPER_METHOD_PTR(POLYCOMPILER, Lucy_PolyCompiler_Serialize);
@@ -176,8 +176,7 @@ PolyCompiler_serialize(PolyCompiler *self, OutStream *outstream) {
 
 PolyCompiler*
 PolyCompiler_deserialize(PolyCompiler *self, InStream *instream) {
-    CharBuf *class_name
-            = CB_Deserialize((CharBuf*)VTable_Make_Obj(CHARBUF), instream);
+    CharBuf *class_name = Freezer_read_charbuf(instream);
     DECREF(class_name); // TODO Don't serialize class name.
     self->children
         = VA_Deserialize((VArray*)VTable_Make_Obj(VARRAY), instream);

http://git-wip-us.apache.org/repos/asf/lucy/blob/44d00c35/core/Lucy/Search/RangeQuery.c
----------------------------------------------------------------------
diff --git a/core/Lucy/Search/RangeQuery.c b/core/Lucy/Search/RangeQuery.c
index a67dc63..4349daf 100644
--- a/core/Lucy/Search/RangeQuery.c
+++ b/core/Lucy/Search/RangeQuery.c
@@ -115,7 +115,7 @@ RangeQuery_to_string(RangeQuery *self) {
 void
 RangeQuery_serialize(RangeQuery *self, OutStream *outstream) {
     OutStream_Write_F32(outstream, self->boost);
-    CB_Serialize(self->field, outstream);
+    Freezer_serialize_charbuf(self->field, outstream);
     if (self->lower_term) {
         OutStream_Write_U8(outstream, true);
         FREEZE(self->lower_term, outstream);
@@ -138,8 +138,7 @@ RangeQuery*
 RangeQuery_deserialize(RangeQuery *self, InStream *instream) {
     // Deserialize components.
     float boost = InStream_Read_F32(instream);
-    CharBuf *field
-        = CB_Deserialize((CharBuf*)VTable_Make_Obj(CHARBUF), instream);
+    CharBuf *field = Freezer_read_charbuf(instream);
     Obj *lower_term = InStream_Read_U8(instream) ? THAW(instream) : NULL;
     Obj *upper_term = InStream_Read_U8(instream) ? THAW(instream) : NULL;
     bool include_lower = InStream_Read_U8(instream);

http://git-wip-us.apache.org/repos/asf/lucy/blob/44d00c35/core/Lucy/Search/SortRule.c
----------------------------------------------------------------------
diff --git a/core/Lucy/Search/SortRule.c b/core/Lucy/Search/SortRule.c
index bb6a419..ee8f2fd 100644
--- a/core/Lucy/Search/SortRule.c
+++ b/core/Lucy/Search/SortRule.c
@@ -20,6 +20,7 @@
 #include "Lucy/Search/SortRule.h"
 #include "Lucy/Store/InStream.h"
 #include "Lucy/Store/OutStream.h"
+#include "Lucy/Util/Freezer.h"
 
 int32_t SortRule_FIELD  = 0;
 int32_t SortRule_SCORE  = 1;
@@ -61,8 +62,7 @@ SortRule*
 SortRule_deserialize(SortRule *self, InStream *instream) {
     self->type = InStream_Read_C32(instream);
     if (self->type == SortRule_FIELD) {
-        self->field
-            = CB_Deserialize((CharBuf*)VTable_Make_Obj(CHARBUF), instream);
+        self->field = Freezer_read_charbuf(instream);
     }
     self->reverse = InStream_Read_C32(instream);
     return self;
@@ -72,7 +72,7 @@ void
 SortRule_serialize(SortRule *self, OutStream *target) {
     OutStream_Write_C32(target, self->type);
     if (self->type == SortRule_FIELD) {
-        CB_Serialize(self->field, target);
+        Freezer_serialize_charbuf(self->field, target);
     }
     OutStream_Write_C32(target, !!self->reverse);
 }

http://git-wip-us.apache.org/repos/asf/lucy/blob/44d00c35/core/Lucy/Search/TermQuery.c
----------------------------------------------------------------------
diff --git a/core/Lucy/Search/TermQuery.c b/core/Lucy/Search/TermQuery.c
index 3e3da4b..e296080 100644
--- a/core/Lucy/Search/TermQuery.c
+++ b/core/Lucy/Search/TermQuery.c
@@ -57,15 +57,14 @@ TermQuery_destroy(TermQuery *self) {
 
 void
 TermQuery_serialize(TermQuery *self, OutStream *outstream) {
-    CB_Serialize(self->field, outstream);
+    Freezer_serialize_charbuf(self->field, outstream);
     FREEZE(self->term, outstream);
     OutStream_Write_F32(outstream, self->boost);
 }
 
 TermQuery*
 TermQuery_deserialize(TermQuery *self, InStream *instream) {
-    self->field
-        = CB_Deserialize((CharBuf*)VTable_Make_Obj(CHARBUF), instream);
+    self->field = Freezer_read_charbuf(instream);
     self->term  = (Obj*)THAW(instream);
     self->boost = InStream_Read_F32(instream);
     return self;

http://git-wip-us.apache.org/repos/asf/lucy/blob/44d00c35/core/LucyX/Search/ProximityQuery.c
----------------------------------------------------------------------
diff --git a/core/LucyX/Search/ProximityQuery.c b/core/LucyX/Search/ProximityQuery.c
index 9ad3396..f81111c 100644
--- a/core/LucyX/Search/ProximityQuery.c
+++ b/core/LucyX/Search/ProximityQuery.c
@@ -79,7 +79,7 @@ S_do_init(ProximityQuery *self, CharBuf *field, VArray *terms, float boost,
 void
 ProximityQuery_serialize(ProximityQuery *self, OutStream *outstream) {
     OutStream_Write_F32(outstream, self->boost);
-    CB_Serialize(self->field, outstream);
+    Freezer_serialize_charbuf(self->field, outstream);
     VA_Serialize(self->terms, outstream);
     OutStream_Write_C32(outstream, self->within);
 }
@@ -87,8 +87,7 @@ ProximityQuery_serialize(ProximityQuery *self, OutStream *outstream) {
 ProximityQuery*
 ProximityQuery_deserialize(ProximityQuery *self, InStream *instream) {
     float boost = InStream_Read_F32(instream);
-    CharBuf *field 
-        = CB_Deserialize((CharBuf*)VTable_Make_Obj(CHARBUF), instream);
+    CharBuf *field = Freezer_read_charbuf(instream);
     VArray *terms 
         = VA_deserialize((VArray*)VTable_Make_Obj(VARRAY), instream);
     uint32_t within = InStream_Read_C32(instream);