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/04 20:23:05 UTC
[lucy-commits] [10/13] git commit: refs/heads/master - Swap in Freezer for ByteBuf
serialization.
Swap in Freezer for ByteBuf serialization.
Replace ByteBuf serialization methods with Freezer routines.
Project: http://git-wip-us.apache.org/repos/asf/lucy/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucy/commit/d04df704
Tree: http://git-wip-us.apache.org/repos/asf/lucy/tree/d04df704
Diff: http://git-wip-us.apache.org/repos/asf/lucy/diff/d04df704
Branch: refs/heads/master
Commit: d04df7049bb86de582531a4d8fae5caaba27db22
Parents: fb14807
Author: Marvin Humphrey <ma...@rectangular.com>
Authored: Fri May 31 15:06:10 2013 -0700
Committer: Marvin Humphrey <ma...@rectangular.com>
Committed: Tue Jun 4 11:13:47 2013 -0700
----------------------------------------------------------------------
core/Clownfish/ByteBuf.c | 22 +++++--------------
core/Clownfish/ByteBuf.cfh | 12 +++++-----
core/Lucy/Index/HighlightReader.c | 3 +-
core/Lucy/Index/HighlightWriter.c | 2 +-
core/Lucy/Util/Freezer.c | 25 +++++++++++++++++++++-
core/Lucy/Util/Freezer.cfh | 9 ++++++++
perl/buildlib/Lucy/Build/Binding/Object.pm | 9 --------
perl/lib/Lucy.pm | 11 ----------
perl/t/026-serialization.t | 4 ++-
9 files changed, 49 insertions(+), 48 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/lucy/blob/d04df704/core/Clownfish/ByteBuf.c
----------------------------------------------------------------------
diff --git a/core/Clownfish/ByteBuf.c b/core/Clownfish/ByteBuf.c
index 3bcc12d..61f1a95 100644
--- a/core/Clownfish/ByteBuf.c
+++ b/core/Clownfish/ByteBuf.c
@@ -62,6 +62,12 @@ BB_new_bytes(const void *bytes, size_t size) {
ByteBuf*
BB_new_steal_bytes(void *bytes, size_t size, size_t capacity) {
ByteBuf *self = (ByteBuf*)VTable_Make_Obj(BYTEBUF);
+ return BB_init_steal_bytes(self, bytes, size, capacity);
+}
+
+ByteBuf*
+BB_init_steal_bytes(ByteBuf *self, void *bytes, size_t size,
+ size_t capacity) {
self->buf = (char*)bytes;
self->size = size;
self->cap = capacity;
@@ -192,22 +198,6 @@ BB_grow(ByteBuf *self, size_t size) {
return self->buf;
}
-void
-BB_serialize(ByteBuf *self, OutStream *target) {
- OutStream_Write_C32(target, self->size);
- OutStream_Write_Bytes(target, self->buf, self->size);
-}
-
-ByteBuf*
-BB_deserialize(ByteBuf *self, InStream *instream) {
- const size_t size = InStream_Read_C32(instream);
- const size_t capacity = size ? size : sizeof(int64_t);
- if (capacity > self->cap) { S_grow(self, capacity); }
- self->size = size;
- InStream_Read_Bytes(instream, self->buf, size);
- return self;
-}
-
int
BB_compare(const void *va, const void *vb) {
const ByteBuf *a = *(const ByteBuf**)va;
http://git-wip-us.apache.org/repos/asf/lucy/blob/d04df704/core/Clownfish/ByteBuf.cfh
----------------------------------------------------------------------
diff --git a/core/Clownfish/ByteBuf.cfh b/core/Clownfish/ByteBuf.cfh
index 6967d08..75c37c8 100644
--- a/core/Clownfish/ByteBuf.cfh
+++ b/core/Clownfish/ByteBuf.cfh
@@ -47,6 +47,12 @@ class Clownfish::ByteBuf cnick BB inherits Clownfish::Obj {
inert incremented ByteBuf*
new_steal_bytes(void *bytes, size_t size, size_t capacity);
+ /** Initialize the ByteBuf and assume ownership of the passed-in string.
+ */
+ public inert ByteBuf*
+ init_steal_bytes(ByteBuf *self, void *bytes, size_t size,
+ size_t capacity);
+
/** Lexical comparison of two ByteBufs, with level of indirection set to
* please qsort and friends.
*/
@@ -119,12 +125,6 @@ class Clownfish::ByteBuf cnick BB inherits Clownfish::Obj {
public int32_t
Hash_Sum(ByteBuf *self);
-
- public void
- Serialize(ByteBuf *self, OutStream *outstream);
-
- public incremented ByteBuf*
- Deserialize(decremented ByteBuf *self, InStream *instream);
}
/**
http://git-wip-us.apache.org/repos/asf/lucy/blob/d04df704/core/Lucy/Index/HighlightReader.c
----------------------------------------------------------------------
diff --git a/core/Lucy/Index/HighlightReader.c b/core/Lucy/Index/HighlightReader.c
index 405107e..8f4b1d6 100644
--- a/core/Lucy/Index/HighlightReader.c
+++ b/core/Lucy/Index/HighlightReader.c
@@ -193,8 +193,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 = Freezer_read_charbuf(dat_in);
- ByteBuf *field_buf
- = BB_Deserialize((ByteBuf*)VTable_Make_Obj(BYTEBUF), dat_in);
+ ByteBuf *field_buf = Freezer_read_bytebuf(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/d04df704/core/Lucy/Index/HighlightWriter.c
----------------------------------------------------------------------
diff --git a/core/Lucy/Index/HighlightWriter.c b/core/Lucy/Index/HighlightWriter.c
index 98bc1f2..175e165 100644
--- a/core/Lucy/Index/HighlightWriter.c
+++ b/core/Lucy/Index/HighlightWriter.c
@@ -129,7 +129,7 @@ HLWriter_add_inverted_doc(HighlightWriter *self, Inverter *inverter,
Inversion *inversion = Inverter_Get_Inversion(inverter);
ByteBuf *tv_buf = HLWriter_TV_Buf(self, inversion);
Freezer_serialize_charbuf(field, dat_out);
- BB_Serialize(tv_buf, dat_out);
+ Freezer_serialize_bytebuf(tv_buf, dat_out);
DECREF(tv_buf);
}
}
http://git-wip-us.apache.org/repos/asf/lucy/blob/d04df704/core/Lucy/Util/Freezer.c
----------------------------------------------------------------------
diff --git a/core/Lucy/Util/Freezer.c b/core/Lucy/Util/Freezer.c
index c78f1c2..1e2c39a 100644
--- a/core/Lucy/Util/Freezer.c
+++ b/core/Lucy/Util/Freezer.c
@@ -52,7 +52,7 @@ Freezer_serialize(Obj *obj, OutStream *outstream) {
Freezer_serialize_charbuf((CharBuf*)obj, outstream);
}
else if (Obj_Is_A(obj, BYTEBUF)) {
- BB_serialize((ByteBuf*)obj, outstream);
+ Freezer_serialize_bytebuf((ByteBuf*)obj, outstream);
}
else if (Obj_Is_A(obj, VARRAY)) {
Freezer_serialize_varray((VArray*)obj, outstream);
@@ -126,7 +126,7 @@ Freezer_deserialize(Obj *obj, InStream *instream) {
obj = (Obj*)Freezer_deserialize_charbuf((CharBuf*)obj, instream);
}
else if (Obj_Is_A(obj, BYTEBUF)) {
- obj = (Obj*)BB_deserialize((ByteBuf*)obj, instream);
+ obj = (Obj*)Freezer_deserialize_bytebuf((ByteBuf*)obj, instream);
}
else if (Obj_Is_A(obj, VARRAY)) {
obj = (Obj*)Freezer_deserialize_varray((VArray*)obj, instream);
@@ -232,6 +232,27 @@ Freezer_read_charbuf(InStream *instream) {
}
void
+Freezer_serialize_bytebuf(ByteBuf *bytebuf, OutStream *outstream) {
+ size_t size = BB_Get_Size(bytebuf);
+ OutStream_Write_C32(outstream, size);
+ OutStream_Write_Bytes(outstream, BB_Get_Buf(bytebuf), size);
+}
+
+ByteBuf*
+Freezer_deserialize_bytebuf(ByteBuf *bytebuf, InStream *instream) {
+ size_t size = InStream_Read_C32(instream);
+ char *buf = MALLOCATE(size);
+ InStream_Read_Bytes(instream, buf, size);
+ return BB_init_steal_bytes(bytebuf, buf, size, size);
+}
+
+ByteBuf*
+Freezer_read_bytebuf(InStream *instream) {
+ ByteBuf *bytebuf = (ByteBuf*)VTable_Make_Obj(BYTEBUF);
+ return Freezer_deserialize_bytebuf(bytebuf, instream);
+}
+
+void
Freezer_serialize_varray(VArray *array, OutStream *outstream) {
uint32_t last_valid_tick = 0;
size_t size = VA_Get_Size(array);
http://git-wip-us.apache.org/repos/asf/lucy/blob/d04df704/core/Lucy/Util/Freezer.cfh
----------------------------------------------------------------------
diff --git a/core/Lucy/Util/Freezer.cfh b/core/Lucy/Util/Freezer.cfh
index dc26c5e..43d6ff2 100644
--- a/core/Lucy/Util/Freezer.cfh
+++ b/core/Lucy/Util/Freezer.cfh
@@ -50,6 +50,15 @@ inert class Lucy::Util::Freezer {
read_charbuf(InStream *instream);
inert void
+ serialize_bytebuf(ByteBuf *bytebuf, OutStream *outstream);
+
+ inert incremented ByteBuf*
+ deserialize_bytebuf(decremented ByteBuf *bytebuf, InStream *instream);
+
+ inert incremented ByteBuf*
+ read_bytebuf(InStream *instream);
+
+ inert void
serialize_varray(VArray *array, OutStream *outstream);
inert incremented VArray*
http://git-wip-us.apache.org/repos/asf/lucy/blob/d04df704/perl/buildlib/Lucy/Build/Binding/Object.pm
----------------------------------------------------------------------
diff --git a/perl/buildlib/Lucy/Build/Binding/Object.pm b/perl/buildlib/Lucy/Build/Binding/Object.pm
index a90b6da..0e3f240 100644
--- a/perl/buildlib/Lucy/Build/Binding/Object.pm
+++ b/perl/buildlib/Lucy/Build/Binding/Object.pm
@@ -98,15 +98,6 @@ CODE:
RETVAL = CFISH_OBJ_TO_SV_NOINC(self);
}
OUTPUT: RETVAL
-
-SV*
-_deserialize(self, instream)
- lucy_ByteBuf *self;
- lucy_InStream *instream;
-CODE:
- lucy_ByteBuf *thawed = Lucy_BB_Deserialize(self, instream);
- RETVAL = (SV*)Lucy_BB_To_Host(thawed);
-OUTPUT: RETVAL
END_XS_CODE
my $binding = Clownfish::CFC::Binding::Perl::Class->new(
http://git-wip-us.apache.org/repos/asf/lucy/blob/d04df704/perl/lib/Lucy.pm
----------------------------------------------------------------------
diff --git a/perl/lib/Lucy.pm b/perl/lib/Lucy.pm
index cf6ab7c..11a1e7e 100644
--- a/perl/lib/Lucy.pm
+++ b/perl/lib/Lucy.pm
@@ -282,17 +282,6 @@ sub error {$Clownfish::Err::error}
}
{
- package Clownfish::ByteBuf;
- our $VERSION = '0.003000';
- $VERSION = eval $VERSION;
- {
- # Override autogenerated deserialize binding.
- no warnings 'redefine';
- sub deserialize { shift->_deserialize(@_) }
- }
-}
-
-{
package Clownfish::ViewByteBuf;
our $VERSION = '0.003000';
$VERSION = eval $VERSION;
http://git-wip-us.apache.org/repos/asf/lucy/blob/d04df704/perl/t/026-serialization.t
----------------------------------------------------------------------
diff --git a/perl/t/026-serialization.t b/perl/t/026-serialization.t
index 9fc7431..89f190c 100644
--- a/perl/t/026-serialization.t
+++ b/perl/t/026-serialization.t
@@ -16,7 +16,7 @@
use strict;
use warnings;
-use Test::More tests => 7;
+use Test::More tests => 6;
package BasicObj;
use base qw( Lucy::Search::Query );
@@ -93,6 +93,8 @@ sub run_test_cycle {
my $thawed = thaw($frozen);
is( $transform->($thawed), $transform->($orig), "$class: freeze/thaw" );
+ return unless $class->can("serialize");
+
my $ram_file = Lucy::Store::RAMFile->new;
my $outstream = Lucy::Store::OutStream->open( file => $ram_file )
or confess Lucy->error;