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/07/17 16:12:38 UTC

[lucy-commits] [18/34] git commit: refs/heads/master - Migrate C host code to IVARS.

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/25f4f658
Tree: http://git-wip-us.apache.org/repos/asf/lucy/tree/25f4f658
Diff: http://git-wip-us.apache.org/repos/asf/lucy/diff/25f4f658

Branch: refs/heads/master
Commit: 25f4f6586011eaa3e6de258723a83f0222d3de2c
Parents: 7ba2ba6
Author: Marvin Humphrey <ma...@rectangular.com>
Authored: Mon Jul 1 08:10:57 2013 -0700
Committer: Marvin Humphrey <ma...@rectangular.com>
Committed: Tue Jul 16 16:08:43 2013 -0700

----------------------------------------------------------------------
 c/src/Lucy/Analysis/RegexTokenizer.c | 17 +++++++------
 c/src/Lucy/Document/Doc.c            | 40 +++++++++++++++++--------------
 c/src/Lucy/Index/DocReader.c         |  7 +++---
 c/src/Lucy/Index/Inverter.c          | 32 +++++++++++++------------
 4 files changed, 53 insertions(+), 43 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucy/blob/25f4f658/c/src/Lucy/Analysis/RegexTokenizer.c
----------------------------------------------------------------------
diff --git a/c/src/Lucy/Analysis/RegexTokenizer.c b/c/src/Lucy/Analysis/RegexTokenizer.c
index e2e5277..4b2bfe6 100644
--- a/c/src/Lucy/Analysis/RegexTokenizer.c
+++ b/c/src/Lucy/Analysis/RegexTokenizer.c
@@ -46,15 +46,16 @@ RegexTokenizer_is_available(void) {
 RegexTokenizer*
 RegexTokenizer_init(RegexTokenizer *self, const CharBuf *pattern) {
     Analyzer_init((Analyzer*)self);
+    RegexTokenizerIVARS *const ivars = RegexTokenizer_IVARS(self);
 
     const char *pattern_ptr;
     if (pattern) {
-        self->pattern = CB_Clone(pattern);
-        pattern_ptr = (char*)CB_Get_Ptr8(self->pattern);
+        ivars->pattern = CB_Clone(pattern);
+        pattern_ptr = (char*)CB_Get_Ptr8(ivars->pattern);
     }
     else {
         pattern_ptr = "\\w+(?:['\\x{2019}]\\w+)*";
-        self->pattern
+        ivars->pattern
             = CB_new_from_trusted_utf8(pattern_ptr, strlen(pattern_ptr));
     }
 
@@ -76,7 +77,7 @@ RegexTokenizer_init(RegexTokenizer *self, const CharBuf *pattern) {
 
     // TODO: Check whether pcre_study improves performance
 
-    self->token_re = re;
+    ivars->token_re = re;
 
     return self;
 }
@@ -90,8 +91,9 @@ RegexTokenizer_set_token_re(RegexTokenizer *self, void *token_re) {
 
 void
 RegexTokenizer_destroy(RegexTokenizer *self) {
-    DECREF(self->pattern);
-    pcre *re = (pcre*)self->token_re;
+    RegexTokenizerIVARS *const ivars = RegexTokenizer_IVARS(self);
+    DECREF(ivars->pattern);
+    pcre *re = (pcre*)ivars->token_re;
     if (re) {
         pcre_free(re);
     }
@@ -102,7 +104,8 @@ void
 RegexTokenizer_tokenize_str(RegexTokenizer *self,
                                  const char *string, size_t string_len,
                                  Inversion *inversion) {
-    pcre      *re          = (pcre*)self->token_re;
+    RegexTokenizerIVARS *const ivars = RegexTokenizer_IVARS(self);
+    pcre      *re          = (pcre*)ivars->token_re;
     int        byte_offset = 0;
     uint32_t   cp_offset   = 0; // Code points
     int        options     = PCRE_NO_UTF8_CHECK;

http://git-wip-us.apache.org/repos/asf/lucy/blob/25f4f658/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/25f4f658/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/25f4f658/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);
     }
 }