Switch Freezer and field_buf over to Blob

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

Branch: refs/heads/master
Commit: 9b2f56786319685eb51132002773e2600e6b1d5a
Parents: 4313e9a
Author: Nick Wellnhofer <[email protected]>
Authored: Mon May 4 16:25:51 2015 +0200
Committer: Nick Wellnhofer <[email protected]>
Committed: Tue May 5 11:23:05 2015 +0200

----------------------------------------------------------------------
 core/Lucy/Index/DocVector.c         | 15 ++++++++-------
 core/Lucy/Index/DocVector.cfh       |  4 ++--
 core/Lucy/Index/HighlightReader.c   |  3 ++-
 core/Lucy/Index/HighlightWriter.c   | 11 +++++++----
 core/Lucy/Index/HighlightWriter.cfh |  2 +-
 core/Lucy/Test/Util/TestFreezer.c   | 11 ++++++-----
 core/Lucy/Util/Freezer.c            | 29 +++++++++++++++--------------
 core/Lucy/Util/Freezer.cfh          | 10 +++++-----
 8 files changed, 46 insertions(+), 39 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucy/blob/9b2f5678/core/Lucy/Index/DocVector.c
----------------------------------------------------------------------
diff --git a/core/Lucy/Index/DocVector.c b/core/Lucy/Index/DocVector.c
index de393c8..b9619b7 100644
--- a/core/Lucy/Index/DocVector.c
+++ b/core/Lucy/Index/DocVector.c
@@ -19,6 +19,7 @@
 
 #include "Lucy/Index/DocVector.h"
 
+#include "Clownfish/Blob.h"
 #include "Clownfish/CharBuf.h"
 #include "Lucy/Index/TermVector.h"
 #include "Lucy/Store/InStream.h"
@@ -28,7 +29,7 @@
 // Extract a document's compressed TermVector data into (term_text =>
 // compressed positional data) pairs.
 static Hash*
-S_extract_tv_cache(ByteBuf *field_buf);
+S_extract_tv_cache(Blob *field_buf);
 
 // Pull a TermVector object out from compressed positional data.
 static TermVector*
@@ -74,15 +75,15 @@ DocVec_Destroy_IMP(DocVector *self) {
 
 void
 DocVec_Add_Field_Buf_IMP(DocVector *self, String *field,
-                         ByteBuf *field_buf) {
+                         Blob *field_buf) {
     DocVectorIVARS *const ivars = DocVec_IVARS(self);
     Hash_Store(ivars->field_bufs, field, INCREF(field_buf));
 }
 
-ByteBuf*
+Blob*
 DocVec_Field_Buf_IMP(DocVector *self, String *field) {
     DocVectorIVARS *const ivars = DocVec_IVARS(self);
-    return (ByteBuf*)Hash_Fetch(ivars->field_bufs, field);
+    return (Blob*)Hash_Fetch(ivars->field_bufs, field);
 }
 
 Vector*
@@ -99,7 +100,7 @@ DocVec_Term_Vector_IMP(DocVector *self, String *field,
 
     // If no cache hit, try to fill cache.
     if (field_vector == NULL) {
-        ByteBuf *field_buf = (ByteBuf*)Hash_Fetch(ivars->field_bufs, field);
+        Blob *field_buf = (Blob*)Hash_Fetch(ivars->field_bufs, field);
 
         // Bail if there's no content or the field isn't highlightable.
         if (field_buf == NULL) { return NULL; }
@@ -118,9 +119,9 @@ DocVec_Term_Vector_IMP(DocVector *self, String *field,
 }
 
 static Hash*
-S_extract_tv_cache(ByteBuf *field_buf) {
+S_extract_tv_cache(Blob *field_buf) {
     Hash       *tv_cache  = Hash_new(0);
-    const char *tv_string = BB_Get_Buf(field_buf);
+    const char *tv_string = Blob_Get_Buf(field_buf);
     int32_t     num_terms = NumUtil_decode_c32(&tv_string);
     CharBuf    *text_buf  = CB_new(0);
 

http://git-wip-us.apache.org/repos/asf/lucy/blob/9b2f5678/core/Lucy/Index/DocVector.cfh
----------------------------------------------------------------------
diff --git a/core/Lucy/Index/DocVector.cfh b/core/Lucy/Index/DocVector.cfh
index 0dde0a1..8a801ad 100644
--- a/core/Lucy/Index/DocVector.cfh
+++ b/core/Lucy/Index/DocVector.cfh
@@ -39,12 +39,12 @@ class Lucy::Index::DocVector nickname DocVec
     /** Add a compressed, encoded TermVector to the object.
      */
     void
-    Add_Field_Buf(DocVector *self, String *field, ByteBuf *field_buf);
+    Add_Field_Buf(DocVector *self, String *field, Blob *field_buf);
 
     /** Return the compressed, encoded TermVector associated with a particular
      * field.
      */
-    ByteBuf*
+    Blob*
     Field_Buf(DocVector *self, String *field);
 
     public void

http://git-wip-us.apache.org/repos/asf/lucy/blob/9b2f5678/core/Lucy/Index/HighlightReader.c
----------------------------------------------------------------------
diff --git a/core/Lucy/Index/HighlightReader.c 
b/core/Lucy/Index/HighlightReader.c
index 345431e..eff0e32 100644
--- a/core/Lucy/Index/HighlightReader.c
+++ b/core/Lucy/Index/HighlightReader.c
@@ -19,6 +19,7 @@
 #define C_LUCY_DEFAULTHIGHLIGHTREADER
 #include "Lucy/Util/ToolSet.h"
 
+#include "Clownfish/Blob.h"
 #include "Lucy/Index/HighlightReader.h"
 #include "Lucy/Index/DocVector.h"
 #include "Lucy/Index/HighlightWriter.h"
@@ -201,7 +202,7 @@ DefHLReader_Fetch_Doc_Vec_IMP(DefaultHighlightReader *self, 
int32_t doc_id) {
     uint32_t num_fields = InStream_Read_C32(dat_in);
     while (num_fields--) {
         String *field = Freezer_read_string(dat_in);
-        ByteBuf *field_buf = Freezer_read_bytebuf(dat_in);
+        Blob *field_buf = Freezer_read_blob(dat_in);
         DocVec_Add_Field_Buf(doc_vec, field, field_buf);
         DECREF(field_buf);
         DECREF(field);

http://git-wip-us.apache.org/repos/asf/lucy/blob/9b2f5678/core/Lucy/Index/HighlightWriter.c
----------------------------------------------------------------------
diff --git a/core/Lucy/Index/HighlightWriter.c 
b/core/Lucy/Index/HighlightWriter.c
index 9655455..fbb4e91 100644
--- a/core/Lucy/Index/HighlightWriter.c
+++ b/core/Lucy/Index/HighlightWriter.c
@@ -20,6 +20,7 @@
 
 #include <stdio.h>
 
+#include "Clownfish/Blob.h"
 #include "Lucy/Index/HighlightWriter.h"
 #include "Lucy/Analysis/Token.h"
 #include "Lucy/Analysis/Inversion.h"
@@ -129,15 +130,15 @@ HLWriter_Add_Inverted_Doc_IMP(HighlightWriter *self, 
Inverter *inverter,
            ) {
             String    *field     = Inverter_Get_Field_Name(inverter);
             Inversion *inversion = Inverter_Get_Inversion(inverter);
-            ByteBuf   *tv_buf    = HLWriter_TV_Buf(self, inversion);
+            Blob      *tv_buf    = HLWriter_TV_Buf(self, inversion);
             Freezer_serialize_string(field, dat_out);
-            Freezer_serialize_bytebuf(tv_buf, dat_out);
+            Freezer_serialize_blob(tv_buf, dat_out);
             DECREF(tv_buf);
         }
     }
 }
 
-ByteBuf*
+Blob*
 HLWriter_TV_Buf_IMP(HighlightWriter *self, Inversion *inversion) {
     const char *last_text = "";
     size_t      last_len = 0;
@@ -204,7 +205,9 @@ HLWriter_TV_Buf_IMP(HighlightWriter *self, Inversion 
*inversion) {
     char *dest = BB_Get_Buf(tv_buf);
     NumUtil_encode_padded_c32(num_postings, &dest);
 
-    return tv_buf;
+    Blob *blob = BB_Yield_Blob(tv_buf);
+    DECREF(tv_buf);
+    return blob;
 }
 
 void

http://git-wip-us.apache.org/repos/asf/lucy/blob/9b2f5678/core/Lucy/Index/HighlightWriter.cfh
----------------------------------------------------------------------
diff --git a/core/Lucy/Index/HighlightWriter.cfh 
b/core/Lucy/Index/HighlightWriter.cfh
index 202509d..00619aa 100644
--- a/core/Lucy/Index/HighlightWriter.cfh
+++ b/core/Lucy/Index/HighlightWriter.cfh
@@ -35,7 +35,7 @@ class Lucy::Index::HighlightWriter nickname HLWriter
     init(HighlightWriter *self, Schema *schema, Snapshot *snapshot,
          Segment *segment, PolyReader *polyreader);
 
-    incremented ByteBuf*
+    incremented Blob*
     TV_Buf(HighlightWriter *self, Inversion *inversion);
 
     public void

http://git-wip-us.apache.org/repos/asf/lucy/blob/9b2f5678/core/Lucy/Test/Util/TestFreezer.c
----------------------------------------------------------------------
diff --git a/core/Lucy/Test/Util/TestFreezer.c 
b/core/Lucy/Test/Util/TestFreezer.c
index 2b924b9..7657a00 100644
--- a/core/Lucy/Test/Util/TestFreezer.c
+++ b/core/Lucy/Test/Util/TestFreezer.c
@@ -18,6 +18,7 @@
 #define TESTLUCY_USE_SHORT_NAMES
 #include "Lucy/Util/ToolSet.h"
 
+#include "Clownfish/Blob.h"
 #include "Clownfish/TestHarness/TestBatchRunner.h"
 #include "Clownfish/TestHarness/TestUtils.h"
 #include "Lucy/Test/Util/TestFreezer.h"
@@ -67,10 +68,10 @@ S_dump_load(Obj *object) {
 }
 
 static void
-test_bytebuf(TestBatchRunner *runner) {
-    ByteBuf *wanted = BB_new_bytes("foobar", 6);
-    ByteBuf *got    = (ByteBuf*)S_freeze_thaw((Obj*)wanted);
-    TEST_TRUE(runner, got && BB_Equals(wanted, (Obj*)got),
+test_blob(TestBatchRunner *runner) {
+    Blob *wanted = Blob_new("foobar", 6);
+    Blob *got    = (Blob*)S_freeze_thaw((Obj*)wanted);
+    TEST_TRUE(runner, got && Blob_Equals(wanted, (Obj*)got),
               "Serialization round trip");
     DECREF(wanted);
     DECREF(got);
@@ -172,7 +173,7 @@ test_varray(TestBatchRunner *runner) {
 void
 TestFreezer_Run_IMP(TestFreezer *self, TestBatchRunner *runner) {
     TestBatchRunner_Plan(runner, (TestBatch*)self, 11);
-    test_bytebuf(runner);
+    test_blob(runner);
     test_string(runner);
     test_hash(runner);
     test_num(runner);

http://git-wip-us.apache.org/repos/asf/lucy/blob/9b2f5678/core/Lucy/Util/Freezer.c
----------------------------------------------------------------------
diff --git a/core/Lucy/Util/Freezer.c b/core/Lucy/Util/Freezer.c
index 91e6b9c..621d63c 100644
--- a/core/Lucy/Util/Freezer.c
+++ b/core/Lucy/Util/Freezer.c
@@ -17,6 +17,7 @@
 #define C_LUCY_FREEZER
 #include "Lucy/Util/ToolSet.h"
 
+#include "Clownfish/Blob.h"
 #include "Clownfish/HashIterator.h"
 #include "Lucy/Util/Freezer.h"
 #include "Lucy/Store/InStream.h"
@@ -54,8 +55,8 @@ Freezer_serialize(Obj *obj, OutStream *outstream) {
     if (Obj_Is_A(obj, STRING)) {
         Freezer_serialize_string((String*)obj, outstream);
     }
-    else if (Obj_Is_A(obj, BYTEBUF)) {
-        Freezer_serialize_bytebuf((ByteBuf*)obj, outstream);
+    else if (Obj_Is_A(obj, BLOB)) {
+        Freezer_serialize_blob((Blob*)obj, outstream);
     }
     else if (Obj_Is_A(obj, VECTOR)) {
         Freezer_serialize_varray((Vector*)obj, outstream);
@@ -127,8 +128,8 @@ Freezer_deserialize(Obj *obj, InStream *instream) {
     if (Obj_Is_A(obj, STRING)) {
         obj = (Obj*)Freezer_deserialize_string((String*)obj, instream);
     }
-    else if (Obj_Is_A(obj, BYTEBUF)) {
-        obj = (Obj*)Freezer_deserialize_bytebuf((ByteBuf*)obj, instream);
+    else if (Obj_Is_A(obj, BLOB)) {
+        obj = (Obj*)Freezer_deserialize_blob((Blob*)obj, instream);
     }
     else if (Obj_Is_A(obj, VECTOR)) {
         obj = (Obj*)Freezer_deserialize_varray((Vector*)obj, instream);
@@ -229,24 +230,24 @@ Freezer_read_string(InStream *instream) {
 }
 
 void
-Freezer_serialize_bytebuf(ByteBuf *bytebuf, OutStream *outstream) {
-    size_t size = BB_Get_Size(bytebuf);
+Freezer_serialize_blob(Blob *blob, OutStream *outstream) {
+    size_t size = Blob_Get_Size(blob);
     OutStream_Write_C32(outstream, size);
-    OutStream_Write_Bytes(outstream, BB_Get_Buf(bytebuf), size);
+    OutStream_Write_Bytes(outstream, Blob_Get_Buf(blob), size);
 }
 
-ByteBuf*
-Freezer_deserialize_bytebuf(ByteBuf *bytebuf, InStream *instream) {
+Blob*
+Freezer_deserialize_blob(Blob *blob, InStream *instream) {
     size_t size = InStream_Read_C32(instream);
     char   *buf = (char*)MALLOCATE(size);
     InStream_Read_Bytes(instream, buf, size);
-    return BB_init_steal_bytes(bytebuf, buf, size, size);
+    return Blob_init_steal(blob, buf, size);
 }
 
-ByteBuf*
-Freezer_read_bytebuf(InStream *instream) {
-    ByteBuf *bytebuf = (ByteBuf*)Class_Make_Obj(BYTEBUF);
-    return Freezer_deserialize_bytebuf(bytebuf, instream);
+Blob*
+Freezer_read_blob(InStream *instream) {
+    Blob *blob = (Blob*)Class_Make_Obj(BLOB);
+    return Freezer_deserialize_blob(blob, instream);
 }
 
 void

http://git-wip-us.apache.org/repos/asf/lucy/blob/9b2f5678/core/Lucy/Util/Freezer.cfh
----------------------------------------------------------------------
diff --git a/core/Lucy/Util/Freezer.cfh b/core/Lucy/Util/Freezer.cfh
index ef6da38..71af3ce 100644
--- a/core/Lucy/Util/Freezer.cfh
+++ b/core/Lucy/Util/Freezer.cfh
@@ -65,13 +65,13 @@ inert class Lucy::Util::Freezer {
     read_string(InStream *instream);
 
     inert void
-    serialize_bytebuf(ByteBuf *bytebuf, OutStream *outstream);
+    serialize_blob(Blob *blob, OutStream *outstream);
 
-    inert incremented ByteBuf*
-    deserialize_bytebuf(decremented ByteBuf *bytebuf, InStream *instream);
+    inert incremented Blob*
+    deserialize_blob(decremented Blob *blob, InStream *instream);
 
-    inert incremented ByteBuf*
-    read_bytebuf(InStream *instream);
+    inert incremented Blob*
+    read_blob(InStream *instream);
 
     inert void
     serialize_varray(Vector *array, OutStream *outstream);

Reply via email to