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:07 UTC

[lucy-commits] [12/13] git commit: refs/heads/master - Swap in Freezer for Num serialization.

Swap in Freezer for Num serialization.

Replace serialization methods for all Num subclasses 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/fb148076
Tree: http://git-wip-us.apache.org/repos/asf/lucy/tree/fb148076
Diff: http://git-wip-us.apache.org/repos/asf/lucy/diff/fb148076

Branch: refs/heads/master
Commit: fb148076be0b5529d705158c0ea43a531f6ba2a7
Parents: a79bfed
Author: Marvin Humphrey <ma...@rectangular.com>
Authored: Fri May 31 14:34:26 2013 -0700
Committer: Marvin Humphrey <ma...@rectangular.com>
Committed: Tue Jun 4 11:13:47 2013 -0700

----------------------------------------------------------------------
 core/Clownfish/Num.c     |   60 -----------------------------------------
 core/Clownfish/Num.cfh   |   30 --------------------
 core/Lucy/Util/Freezer.c |   36 +++++++++++++++++-------
 3 files changed, 26 insertions(+), 100 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucy/blob/fb148076/core/Clownfish/Num.c
----------------------------------------------------------------------
diff --git a/core/Clownfish/Num.c b/core/Clownfish/Num.c
index 8d49ab1..ae170a0 100644
--- a/core/Clownfish/Num.c
+++ b/core/Clownfish/Num.c
@@ -146,17 +146,6 @@ Float32_mimic(Float32 *self, Obj *other) {
     self->value = twin->value;
 }
 
-void
-Float32_serialize(Float32 *self, OutStream *outstream) {
-    OutStream_Write_F32(outstream, self->value);
-}
-
-Float32*
-Float32_deserialize(Float32 *self, InStream *instream) {
-    float value = InStream_Read_F32(instream);
-    return Float32_init(self, value);
-}
-
 /***************************************************************************/
 
 Float64*
@@ -208,17 +197,6 @@ Float64_hash_sum(Float64 *self) {
     return ints[0] ^ ints[1];
 }
 
-void
-Float64_serialize(Float64 *self, OutStream *outstream) {
-    OutStream_Write_F64(outstream, self->value);
-}
-
-Float64*
-Float64_deserialize(Float64 *self, InStream *instream) {
-    double value = InStream_Read_F64(instream);
-    return Float64_init(self, value);
-}
-
 /***************************************************************************/
 
 Integer32*
@@ -269,17 +247,6 @@ Int32_hash_sum(Integer32 *self) {
     return self->value;
 }
 
-void
-Int32_serialize(Integer32 *self, OutStream *outstream) {
-    OutStream_Write_C32(outstream, (uint32_t)self->value);
-}
-
-Integer32*
-Int32_deserialize(Integer32 *self, InStream *instream) {
-    int32_t value = (int32_t)InStream_Read_C32(instream);
-    return Int32_init(self, value);
-}
-
 /***************************************************************************/
 
 Integer64*
@@ -348,17 +315,6 @@ Int64_equals(Integer64 *self, Obj *other) {
     return true;
 }
 
-void
-Int64_serialize(Integer64 *self, OutStream *outstream) {
-    OutStream_Write_C64(outstream, (uint64_t)self->value);
-}
-
-Integer64*
-Int64_deserialize(Integer64 *self, InStream *instream) {
-    int64_t value = (int64_t)InStream_Read_C64(instream);
-    return Int64_init(self, value);
-}
-
 /***************************************************************************/
 
 
@@ -428,22 +384,6 @@ Bool_equals(BoolNum *self, Obj *other) {
     return self == (BoolNum*)other;
 }
 
-void
-Bool_serialize(BoolNum *self, OutStream *outstream) {
-    OutStream_Write_U8(outstream, (uint8_t)self->value);
-}
-
-BoolNum*
-Bool_deserialize(BoolNum *self, InStream *instream) {
-    bool value = (bool)InStream_Read_U8(instream);
-    if (self && self != CFISH_TRUE && self != CFISH_FALSE) {
-        Bool_Dec_RefCount_t super_decref
-            = SUPER_METHOD_PTR(BOOLNUM, Lucy_Bool_Dec_RefCount);
-        super_decref(self);
-    }
-    return value ? CFISH_TRUE : CFISH_FALSE;
-}
-
 BoolNum*
 Bool_inc_refcount(BoolNum *self) {
     return self;

http://git-wip-us.apache.org/repos/asf/lucy/blob/fb148076/core/Clownfish/Num.cfh
----------------------------------------------------------------------
diff --git a/core/Clownfish/Num.cfh b/core/Clownfish/Num.cfh
index 0ff37be..57f74ee 100644
--- a/core/Clownfish/Num.cfh
+++ b/core/Clownfish/Num.cfh
@@ -86,12 +86,6 @@ class Clownfish::Float32 inherits Clownfish::FloatNum {
     public int32_t
     Hash_Sum(Float32 *self);
 
-    public void
-    Serialize(Float32 *self, OutStream *outstream);
-
-    public incremented Float32*
-    Deserialize(decremented Float32 *self, InStream *instream);
-
     public incremented Float32*
     Clone(Float32 *self);
 
@@ -129,12 +123,6 @@ class Clownfish::Float64 inherits Clownfish::FloatNum {
     public int32_t
     Hash_Sum(Float64 *self);
 
-    public void
-    Serialize(Float64 *self, OutStream *outstream);
-
-    public incremented Float64*
-    Deserialize(decremented Float64 *self, InStream *instream);
-
     public incremented Float64*
     Clone(Float64 *self);
 
@@ -173,12 +161,6 @@ class Clownfish::Integer32 cnick Int32
     public int32_t
     Hash_Sum(Integer32 *self);
 
-    public void
-    Serialize(Integer32 *self, OutStream *outstream);
-
-    public incremented Integer32*
-    Deserialize(decremented Integer32 *self, InStream *instream);
-
     public incremented Integer32*
     Clone(Integer32 *self);
 
@@ -221,12 +203,6 @@ class Clownfish::Integer64 cnick Int64
     public bool
     Equals(Integer64 *self, Obj *other);
 
-    public void
-    Serialize(Integer64 *self, OutStream *outstream);
-
-    public incremented Integer64*
-    Deserialize(decremented Integer64 *self, InStream *instream);
-
     public incremented Integer64*
     Clone(Integer64 *self);
 
@@ -275,12 +251,6 @@ class Clownfish::BoolNum cnick Bool inherits Clownfish::IntNum {
     public int32_t
     Hash_Sum(BoolNum *self);
 
-    public void
-    Serialize(BoolNum *self, OutStream *outstream);
-
-    public incremented BoolNum*
-    Deserialize(decremented BoolNum *self, InStream *instream);
-
     /* Returns self. */
     public incremented BoolNum*
     Clone(BoolNum *self);

http://git-wip-us.apache.org/repos/asf/lucy/blob/fb148076/core/Lucy/Util/Freezer.c
----------------------------------------------------------------------
diff --git a/core/Lucy/Util/Freezer.c b/core/Lucy/Util/Freezer.c
index 3d43160..c78f1c2 100644
--- a/core/Lucy/Util/Freezer.c
+++ b/core/Lucy/Util/Freezer.c
@@ -63,21 +63,26 @@ Freezer_serialize(Obj *obj, OutStream *outstream) {
     else if (Obj_Is_A(obj, NUM)) {
         if (Obj_Is_A(obj, INTNUM)) {
             if (Obj_Is_A(obj, BOOLNUM)) {
-                Bool_serialize((BoolNum*)obj, outstream);
+                bool val = Bool_Get_Value((BoolNum*)obj);
+                OutStream_Write_U8(outstream, (uint8_t)val);
             }
             else if (Obj_Is_A(obj, INTEGER32)) {
-                Int32_serialize((Integer32*)obj, outstream);
+                int32_t val = Int32_Get_Value((Integer32*)obj);
+                OutStream_Write_C32(outstream, (uint32_t)val);
             }
             else if (Obj_Is_A(obj, INTEGER64)) {
-                Int64_serialize((Integer64*)obj, outstream);
+                int64_t val = Int64_Get_Value((Integer64*)obj);
+                OutStream_Write_C64(outstream, (uint64_t)val);
             }
         }
         else if (Obj_Is_A(obj, FLOATNUM)) {
             if (Obj_Is_A(obj, FLOAT32)) {
-                Float32_serialize((Float32*)obj, outstream);
+                float val = Float32_Get_Value((Float32*)obj);
+                OutStream_Write_F32(outstream, val);
             }
             else if (Obj_Is_A(obj, FLOAT64)) {
-                Float64_serialize((Float64*)obj, outstream);
+                double val = Float64_Get_Value((Float64*)obj);
+                OutStream_Write_F64(outstream, val);
             }
         }
     }
@@ -132,21 +137,32 @@ Freezer_deserialize(Obj *obj, InStream *instream) {
     else if (Obj_Is_A(obj, NUM)) {
         if (Obj_Is_A(obj, INTNUM)) {
             if (Obj_Is_A(obj, BOOLNUM)) {
-                obj = (Obj*)Bool_deserialize((BoolNum*)obj, instream);
+                bool value = (bool)InStream_Read_U8(instream);
+                BoolNum *self = (BoolNum*)obj;
+                if (self && self != CFISH_TRUE && self != CFISH_FALSE) {
+                    Bool_Dec_RefCount_t super_decref
+                        = SUPER_METHOD_PTR(BOOLNUM, Lucy_Bool_Dec_RefCount);
+                    super_decref(self);
+                }
+                obj = value ? CFISH_TRUE : CFISH_FALSE;
             }
             else if (Obj_Is_A(obj, INTEGER32)) {
-                obj = (Obj*)Int32_deserialize((Integer32*)obj, instream);
+                int32_t value = (int32_t)InStream_Read_C32(instream);
+                obj = (Obj*)Int32_init((Integer32*)obj, value);
             }
             else if (Obj_Is_A(obj, INTEGER64)) {
-                obj = (Obj*)Int64_deserialize((Integer64*)obj, instream);
+                int64_t value = (int64_t)InStream_Read_C64(instream);
+                obj = (Obj*)Int64_init((Integer64*)obj, value);
             }
         }
         else if (Obj_Is_A(obj, FLOATNUM)) {
             if (Obj_Is_A(obj, FLOAT32)) {
-                obj = (Obj*)Float32_deserialize((Float32*)obj, instream);
+                float value = InStream_Read_F32(instream);
+                obj = (Obj*)Float32_init((Float32*)obj, value);
             }
             else if (Obj_Is_A(obj, FLOAT64)) {
-                obj = (Obj*)Float64_deserialize((Float64*)obj, instream);
+                double value = InStream_Read_F64(instream);
+                obj = (Obj*)Float64_init((Float64*)obj, value);
             }
         }
     }