lucy-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mar...@apache.org
Subject [lucy-commits] [7/9] git commit: refs/heads/ivars-wip1 - Migrate C host code to IVARS.
Date Mon, 01 Jul 2013 16:47:28 GMT
Migrate C host code to IVARS.

Migrate host-specific code for C to use IVARS rather than access struct
members through `self`.


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

Branch: refs/heads/ivars-wip1
Commit: d3edeee9a80fc60d9e48939153fe75f31d850a4b
Parents: f19a6af
Author: Marvin Humphrey <marvin@rectangular.com>
Authored: Mon Jul 1 08:10:57 2013 -0700
Committer: Marvin Humphrey <marvin@rectangular.com>
Committed: Mon Jul 1 08:46:22 2013 -0700

----------------------------------------------------------------------
 c/src/Lucy/Document/Doc.c    | 40 +++++++++++++++++++++------------------
 c/src/Lucy/Index/DocReader.c |  7 ++++---
 c/src/Lucy/Index/Inverter.c  | 32 ++++++++++++++++---------------
 3 files changed, 43 insertions(+), 36 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucy/blob/d3edeee9/c/src/Lucy/Document/Doc.c
----------------------------------------------------------------------
diff --git a/c/src/Lucy/Document/Doc.c b/c/src/Lucy/Document/Doc.c
index f0fb2d4..74cfef8 100644
--- a/c/src/Lucy/Document/Doc.c
+++ b/c/src/Lucy/Document/Doc.c
@@ -30,6 +30,7 @@
 
 Doc*
 Doc_init(Doc *self, void *fields, int32_t doc_id) {
+    DocIVARS *const ivars = Doc_IVARS(self);
     Hash *hash;
 
     if (fields) {
@@ -39,49 +40,52 @@ Doc_init(Doc *self, void *fields, int32_t doc_id) {
     else {
         hash = Hash_new(0);
     }
-    self->fields = hash;
-    self->doc_id = doc_id;
+    ivars->fields = hash;
+    ivars->doc_id = doc_id;
 
     return self;
 }
 
 void
 Doc_set_fields(Doc *self, void *fields) {
-    DECREF(self->fields);
-    self->fields = CERTIFY(fields, HASH);
+    DocIVARS *const ivars = Doc_IVARS(self);
+    DECREF(ivars->fields);
+    ivars->fields = CERTIFY(fields, HASH);
 }
 
 uint32_t
 Doc_get_size(Doc *self) {
-    Hash *hash = (Hash *)self->fields;
+    Hash *hash = (Hash*)Doc_IVARS(self)->fields;
     return Hash_Get_Size(hash);
 }
 
 void
 Doc_store(Doc *self, const CharBuf *field, Obj *value) {
-    Hash *hash = (Hash *)self->fields;
+    Hash *hash = (Hash*)Doc_IVARS(self)->fields;
     Hash_Store(hash, (Obj *)field, value);
     INCREF(value);
 }
 
 void
 Doc_serialize(Doc *self, OutStream *outstream) {
-    Hash *hash = (Hash *)self->fields;
+    DocIVARS *const ivars = Doc_IVARS(self);
+    Hash *hash = (Hash*)ivars->fields;
     Freezer_serialize_hash(hash, outstream);
-    OutStream_Write_C32(outstream, self->doc_id);
+    OutStream_Write_C32(outstream, ivars->doc_id);
 }
 
 Doc*
 Doc_deserialize(Doc *self, InStream *instream) {
-     self->fields = Freezer_read_hash(instream);
-     self->doc_id = InStream_Read_C32(instream);
-     return self;
+    DocIVARS *const ivars = Doc_IVARS(self);
+    ivars->fields = Freezer_read_hash(instream);
+    ivars->doc_id = InStream_Read_C32(instream);
+    return self;
 }
 
 Obj*
 Doc_extract(Doc *self, CharBuf *field,
                  ViewCharBuf *target) {
-    Hash *hash = (Hash *)self->fields;
+    Hash *hash = (Hash*)Doc_IVARS(self)->fields;
     Obj  *obj  = Hash_Fetch(hash, (Obj *)field);
 
     if (target && obj && Obj_Is_A(obj, CHARBUF)) {
@@ -115,17 +119,17 @@ Doc_load(Doc *self, Obj *dump) {
 
 bool
 Doc_equals(Doc *self, Obj *other) {
-    Doc *twin = (Doc*)other;
-
-    if (twin == self)                    { return true;  }
+    if ((Doc*)other == self)   { return true;  }
     if (!Obj_Is_A(other, DOC)) { return false; }
-
-    return Hash_Equals((Hash*)self->fields, (Obj*)twin->fields);
+    DocIVARS *const ivars = Doc_IVARS(self);
+    DocIVARS *const ovars = Doc_IVARS((Doc*)other);
+    return Hash_Equals((Hash*)ivars->fields, (Obj*)ovars->fields);
 }
 
 void
 Doc_destroy(Doc *self) {
-    DECREF(self->fields);
+    DocIVARS *const ivars = Doc_IVARS(self);
+    DECREF(ivars->fields);
     SUPER_DESTROY(self, DOC);
 }
 

http://git-wip-us.apache.org/repos/asf/lucy/blob/d3edeee9/c/src/Lucy/Index/DocReader.c
----------------------------------------------------------------------
diff --git a/c/src/Lucy/Index/DocReader.c b/c/src/Lucy/Index/DocReader.c
index 79fcd4f..ee56bd1 100644
--- a/c/src/Lucy/Index/DocReader.c
+++ b/c/src/Lucy/Index/DocReader.c
@@ -34,9 +34,10 @@
 
 HitDoc*
 DefDocReader_fetch_doc(DefaultDocReader *self, int32_t doc_id) {
-    Schema   *const schema = self->schema;
-    InStream *const dat_in = self->dat_in;
-    InStream *const ix_in  = self->ix_in;
+    DefaultDocReaderIVARS *const ivars = DefDocReader_IVARS(self);
+    Schema   *const schema = ivars->schema;
+    InStream *const dat_in = ivars->dat_in;
+    InStream *const ix_in  = ivars->ix_in;
     Hash     *const fields = Hash_new(1);
     int64_t   start;
     uint32_t  num_fields;

http://git-wip-us.apache.org/repos/asf/lucy/blob/d3edeee9/c/src/Lucy/Index/Inverter.c
----------------------------------------------------------------------
diff --git a/c/src/Lucy/Index/Inverter.c b/c/src/Lucy/Index/Inverter.c
index 0700075..22c78a1 100644
--- a/c/src/Lucy/Index/Inverter.c
+++ b/c/src/Lucy/Index/Inverter.c
@@ -33,15 +33,15 @@
 #include "Lucy/Plan/Schema.h"
 
 static InverterEntry*
-S_fetch_entry(Inverter *self, CharBuf *field) {
-    Schema *const schema = self->schema;
-    int32_t field_num = Seg_Field_Num(self->segment, field);
+S_fetch_entry(InverterIVARS *ivars, CharBuf *field) {
+    Schema *const schema = ivars->schema;
+    int32_t field_num = Seg_Field_Num(ivars->segment, field);
     if (!field_num) {
         // This field seems not to be in the segment yet.  Try to find it in
         // the Schema.
         if (Schema_Fetch_Type(schema, field)) {
             // The field is in the Schema.  Get a field num from the Segment.
-            field_num = Seg_Add_Field(self->segment, field);
+            field_num = Seg_Add_Field(ivars->segment, field);
         }
         else {
             // We've truly failed to find the field.  The user must
@@ -51,16 +51,17 @@ S_fetch_entry(Inverter *self, CharBuf *field) {
     }
 
     InverterEntry *entry
-        = (InverterEntry*)VA_Fetch(self->entry_pool, field_num);
+        = (InverterEntry*)VA_Fetch(ivars->entry_pool, field_num);
     if (!entry) {
         entry = InvEntry_new(schema, (CharBuf*)field, field_num);
-        VA_Store(self->entry_pool, field_num, (Obj*)entry);
+        VA_Store(ivars->entry_pool, field_num, (Obj*)entry);
     }
     return entry;
 }
 
 void
 Inverter_invert_doc(Inverter *self, Doc *doc) {
+    InverterIVARS *const ivars = Inverter_IVARS(self);
     Hash *const fields = (Hash*)Doc_Get_Fields(doc);
     uint32_t   num_keys     = Hash_Iterate(fields);
 
@@ -72,8 +73,9 @@ Inverter_invert_doc(Inverter *self, Doc *doc) {
         Obj *key, *obj;
         Hash_Next(fields, &key, &obj);
         CharBuf *field = (CharBuf*)CERTIFY(key, CHARBUF);
-        InverterEntry *inv_entry = S_fetch_entry(self, field);
-        FieldType *type = inv_entry->type;
+        InverterEntry *inventry = S_fetch_entry(ivars, field);
+        InverterEntryIVARS *inventry_ivars = InvEntry_IVARS(inventry);
+        FieldType *type = inventry_ivars->type;
 
         // Get the field value.
         switch (FType_Primitive_ID(type) & FType_PRIMITIVE_ID_MASK) {
@@ -81,7 +83,7 @@ Inverter_invert_doc(Inverter *self, Doc *doc) {
                     CharBuf *char_buf
                         = (CharBuf*)CERTIFY(obj, CHARBUF);
                     ViewCharBuf *value
-                        = (ViewCharBuf*)inv_entry->value;
+                        = (ViewCharBuf*)inventry_ivars->value;
                     ViewCB_Assign(value, char_buf);
                     break;
                 }
@@ -89,31 +91,31 @@ Inverter_invert_doc(Inverter *self, Doc *doc) {
                     ByteBuf *byte_buf
                         = (ByteBuf*)CERTIFY(obj, BYTEBUF);
                     ViewByteBuf *value
-                        = (ViewByteBuf*)inv_entry->value;
+                        = (ViewByteBuf*)inventry_ivars->value;
                     ViewBB_Assign(value, byte_buf);
                     break;
                 }
             case FType_INT32: {
                     int32_t int_val = (int32_t)Obj_To_I64(obj);
-                    Integer32* value = (Integer32*)inv_entry->value;
+                    Integer32* value = (Integer32*)inventry_ivars->value;
                     Int32_Set_Value(value, int_val);
                     break;
                 }
             case FType_INT64: {
                     int64_t int_val = Obj_To_I64(obj);
-                    Integer64* value = (Integer64*)inv_entry->value;
+                    Integer64* value = (Integer64*)inventry_ivars->value;
                     Int64_Set_Value(value, int_val);
                     break;
                 }
             case FType_FLOAT32: {
                     float float_val = (float)Obj_To_F64(obj);
-                    Float32* value = (Float32*)inv_entry->value;
+                    Float32* value = (Float32*)inventry_ivars->value;
                     Float32_Set_Value(value, float_val);
                     break;
                 }
             case FType_FLOAT64: {
                     double float_val = Obj_To_F64(obj);
-                    Float64* value = (Float64*)inv_entry->value;
+                    Float64* value = (Float64*)inventry_ivars->value;
                     Float64_Set_Value(value, float_val);
                     break;
                 }
@@ -121,7 +123,7 @@ Inverter_invert_doc(Inverter *self, Doc *doc) {
                 THROW(ERR, "Unrecognized type: %o", type);
         }
 
-        Inverter_Add_Field(self, inv_entry);
+        Inverter_Add_Field(self, inventry);
     }
 }
 


Mime
View raw message