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

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

Migrate Perl host code to IVARS.

Migrate host-specific code for Perl 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/811358d9
Tree: http://git-wip-us.apache.org/repos/asf/lucy/tree/811358d9
Diff: http://git-wip-us.apache.org/repos/asf/lucy/diff/811358d9

Branch: refs/heads/master
Commit: 811358d9f87133f6987eb64259f4b4bbcaafddc2
Parents: ff0ec8d
Author: Marvin Humphrey <ma...@rectangular.com>
Authored: Mon Jul 1 08:45:46 2013 -0700
Committer: Marvin Humphrey <ma...@rectangular.com>
Committed: Tue Jul 16 16:08:43 2013 -0700

----------------------------------------------------------------------
 perl/xs/Lucy/Analysis/RegexTokenizer.c | 27 +++++++------
 perl/xs/Lucy/Document/Doc.c            | 60 ++++++++++++++++-------------
 perl/xs/Lucy/Index/DocReader.c         |  7 ++--
 perl/xs/Lucy/Index/Inverter.c          | 27 +++++++------
 4 files changed, 69 insertions(+), 52 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucy/blob/811358d9/perl/xs/Lucy/Analysis/RegexTokenizer.c
----------------------------------------------------------------------
diff --git a/perl/xs/Lucy/Analysis/RegexTokenizer.c b/perl/xs/Lucy/Analysis/RegexTokenizer.c
index d175b59..86738fc 100644
--- a/perl/xs/Lucy/Analysis/RegexTokenizer.c
+++ b/perl/xs/Lucy/Analysis/RegexTokenizer.c
@@ -42,6 +42,7 @@ lucy_RegexTokenizer*
 lucy_RegexTokenizer_init(lucy_RegexTokenizer *self,
                          const cfish_CharBuf *pattern) {
     lucy_Analyzer_init((lucy_Analyzer*)self);
+    lucy_RegexTokenizerIVARS *const ivars = lucy_RegexTokenizer_IVARS(self);
     #define DEFAULT_PATTERN "\\w+(?:['\\x{2019}]\\w+)*"
     if (pattern) {
         if (Cfish_CB_Find_Str(pattern, "\\p", 2) != -1
@@ -50,15 +51,15 @@ lucy_RegexTokenizer_init(lucy_RegexTokenizer *self,
             CFISH_DECREF(self);
             THROW(CFISH_ERR, "\\p and \\P constructs forbidden");
         }
-        self->pattern = Cfish_CB_Clone(pattern);
+        ivars->pattern = Cfish_CB_Clone(pattern);
     }
     else {
-        self->pattern = cfish_CB_new_from_trusted_utf8(
+        ivars->pattern = cfish_CB_new_from_trusted_utf8(
                             DEFAULT_PATTERN, sizeof(DEFAULT_PATTERN) - 1);
     }
 
     // Acquire a compiled regex engine for matching one token.
-    SV *token_re_sv = S_compile_token_re(self->pattern);
+    SV *token_re_sv = S_compile_token_re(ivars->pattern);
     S_set_token_re_but_not_pattern(self, SvRV(token_re_sv));
     SvREFCNT_dec(token_re_sv);
 
@@ -86,6 +87,7 @@ S_compile_token_re(const cfish_CharBuf *pattern) {
 
 static void
 S_set_token_re_but_not_pattern(lucy_RegexTokenizer *self, void *token_re) {
+    lucy_RegexTokenizerIVARS *const ivars = lucy_RegexTokenizer_IVARS(self);
 #if (PERL_VERSION > 10)
     REGEXP *rx = SvRX((SV*)token_re);
 #else
@@ -102,17 +104,18 @@ S_set_token_re_but_not_pattern(lucy_RegexTokenizer *self, void *token_re) {
         THROW(CFISH_ERR, "Failed to extract REGEXP from token_re '%s'",
               SvPV_nolen((SV*)token_re));
     }
-    if (self->token_re) { ReREFCNT_dec(((REGEXP*)self->token_re)); }
-    self->token_re = rx;
-    (void)ReREFCNT_inc(((REGEXP*)self->token_re));
+    if (ivars->token_re) { ReREFCNT_dec(((REGEXP*)ivars->token_re)); }
+    ivars->token_re = rx;
+    (void)ReREFCNT_inc(((REGEXP*)ivars->token_re));
 }
 
 static void
 S_set_pattern_from_token_re(lucy_RegexTokenizer *self, void *token_re) {
+    lucy_RegexTokenizerIVARS *const ivars = lucy_RegexTokenizer_IVARS(self);
     SV *rv = newRV((SV*)token_re);
     STRLEN len = 0;
     char *ptr = SvPVutf8((SV*)rv, len);
-    Cfish_CB_Mimic_Str(self->pattern, ptr, len);
+    Cfish_CB_Mimic_Str(ivars->pattern, ptr, len);
     SvREFCNT_dec(rv);
 }
 
@@ -125,8 +128,9 @@ lucy_RegexTokenizer_set_token_re(lucy_RegexTokenizer *self, void *token_re) {
 
 void
 lucy_RegexTokenizer_destroy(lucy_RegexTokenizer *self) {
-    CFISH_DECREF(self->pattern);
-    ReREFCNT_dec(((REGEXP*)self->token_re));
+    lucy_RegexTokenizerIVARS *const ivars = lucy_RegexTokenizer_IVARS(self);
+    CFISH_DECREF(ivars->pattern);
+    ReREFCNT_dec(((REGEXP*)ivars->token_re));
     CFISH_SUPER_DESTROY(self, LUCY_REGEXTOKENIZER);
 }
 
@@ -134,13 +138,14 @@ void
 lucy_RegexTokenizer_tokenize_str(lucy_RegexTokenizer *self,
                                  const char *string, size_t string_len,
                                  lucy_Inversion *inversion) {
+    lucy_RegexTokenizerIVARS *const ivars = lucy_RegexTokenizer_IVARS(self);
     uint32_t   num_code_points = 0;
     SV        *wrapper    = sv_newmortal();
 #if (PERL_VERSION > 10)
-    REGEXP    *rx         = (REGEXP*)self->token_re;
+    REGEXP    *rx         = (REGEXP*)ivars->token_re;
     regexp    *rx_struct  = (regexp*)SvANY(rx);
 #else
-    REGEXP    *rx         = (REGEXP*)self->token_re;
+    REGEXP    *rx         = (REGEXP*)ivars->token_re;
     regexp    *rx_struct  = rx;
 #endif
     char      *string_beg = (char*)string;

http://git-wip-us.apache.org/repos/asf/lucy/blob/811358d9/perl/xs/Lucy/Document/Doc.c
----------------------------------------------------------------------
diff --git a/perl/xs/Lucy/Document/Doc.c b/perl/xs/Lucy/Document/Doc.c
index c20c2b0..220a7bf 100644
--- a/perl/xs/Lucy/Document/Doc.c
+++ b/perl/xs/Lucy/Document/Doc.c
@@ -23,32 +23,36 @@
 
 lucy_Doc*
 lucy_Doc_init(lucy_Doc *self, void *fields, int32_t doc_id) {
+    lucy_DocIVARS *const ivars = lucy_Doc_IVARS(self);
     // Assign.
     if (fields) {
         if (SvTYPE((SV*)fields) != SVt_PVHV) { THROW(CFISH_ERR, "Not a hash"); }
-        self->fields = SvREFCNT_inc((SV*)fields);
+        ivars->fields = SvREFCNT_inc((SV*)fields);
     }
     else {
-        self->fields = newHV();
+        ivars->fields = newHV();
     }
-    self->doc_id = doc_id;
+    ivars->doc_id = doc_id;
 
     return self;
 }
 
 void
 lucy_Doc_set_fields(lucy_Doc *self, void *fields) {
-    if (self->fields) { SvREFCNT_dec((SV*)self->fields); }
-    self->fields = SvREFCNT_inc((SV*)fields);
+    lucy_DocIVARS *const ivars = lucy_Doc_IVARS(self);
+    if (ivars->fields) { SvREFCNT_dec((SV*)ivars->fields); }
+    ivars->fields = SvREFCNT_inc((SV*)fields);
 }
 
 uint32_t
 lucy_Doc_get_size(lucy_Doc *self) {
-    return self->fields ? HvKEYS((HV*)self->fields) : 0;
+    lucy_DocIVARS *const ivars = lucy_Doc_IVARS(self);
+    return ivars->fields ? HvKEYS((HV*)ivars->fields) : 0;
 }
 
 void
 lucy_Doc_store(lucy_Doc *self, const cfish_CharBuf *field, cfish_Obj *value) {
+    lucy_DocIVARS *const ivars = lucy_Doc_IVARS(self);
     char   *key      = (char*)Cfish_CB_Get_Ptr8(field);
     size_t  key_size = Cfish_CB_Get_Size(field);
     SV *key_sv = newSVpvn(key, key_size);
@@ -58,19 +62,20 @@ lucy_Doc_store(lucy_Doc *self, const cfish_CharBuf *field, cfish_Obj *value) {
                  ? XSBind_cb_to_sv((cfish_CharBuf*)value)
                  : (SV*)Cfish_Obj_To_Host(value);
     SvUTF8_on(key_sv);
-    (void)hv_store_ent((HV*)self->fields, key_sv, val_sv, 0);
+    (void)hv_store_ent((HV*)ivars->fields, key_sv, val_sv, 0);
     // TODO: make this a thread-local instead of creating it every time?
     SvREFCNT_dec(key_sv);
 }
 
 static SV*
 S_nfreeze_fields(lucy_Doc *self) {
+    lucy_DocIVARS *const ivars = lucy_Doc_IVARS(self);
     dSP;
     ENTER;
     SAVETMPS;
     EXTEND(SP, 1);
     PUSHMARK(SP);
-    mPUSHs((SV*)newRV_inc((SV*)self->fields));
+    mPUSHs((SV*)newRV_inc((SV*)ivars->fields));
     PUTBACK;
     call_pv("Storable::nfreeze", G_SCALAR);
     SPAGAIN;
@@ -84,7 +89,8 @@ S_nfreeze_fields(lucy_Doc *self) {
 
 void
 lucy_Doc_serialize(lucy_Doc *self, lucy_OutStream *outstream) {
-    Lucy_OutStream_Write_C32(outstream, self->doc_id);
+    lucy_DocIVARS *const ivars = lucy_Doc_IVARS(self);
+    Lucy_OutStream_Write_C32(outstream, ivars->doc_id);
     SV *frozen = S_nfreeze_fields(self);
     STRLEN len;
     char *buf = SvPV(frozen, len);
@@ -138,8 +144,9 @@ lucy_Doc_deserialize(lucy_Doc *self, lucy_InStream *instream) {
 cfish_Obj*
 lucy_Doc_extract(lucy_Doc *self, cfish_CharBuf *field,
                  cfish_ViewCharBuf *target) {
+    lucy_DocIVARS *const ivars = lucy_Doc_IVARS(self);
     cfish_Obj *retval = NULL;
-    SV **sv_ptr = hv_fetch((HV*)self->fields, (char*)Cfish_CB_Get_Ptr8(field),
+    SV **sv_ptr = hv_fetch((HV*)ivars->fields, (char*)Cfish_CB_Get_Ptr8(field),
                            Cfish_CB_Get_Size(field), 0);
 
     if (sv_ptr && XSBind_sv_defined(*sv_ptr)) {
@@ -170,13 +177,14 @@ lucy_Doc_to_host(lucy_Doc *self) {
 
 cfish_Hash*
 lucy_Doc_dump(lucy_Doc *self) {
+    lucy_DocIVARS *const ivars = lucy_Doc_IVARS(self);
     cfish_Hash *dump = cfish_Hash_new(0);
     Cfish_Hash_Store_Str(dump, "_class", 6,
                         (cfish_Obj*)Cfish_CB_Clone(Lucy_Doc_Get_Class_Name(self)));
     Cfish_Hash_Store_Str(dump, "doc_id", 7,
-                        (cfish_Obj*)cfish_CB_newf("%i32", self->doc_id));
+                        (cfish_Obj*)cfish_CB_newf("%i32", ivars->doc_id));
     Cfish_Hash_Store_Str(dump, "fields", 6,
-                        XSBind_perl_to_cfish((SV*)self->fields));
+                        XSBind_perl_to_cfish((SV*)ivars->fields));
     return dump;
 }
 
@@ -197,8 +205,9 @@ lucy_Doc_load(lucy_Doc *self, cfish_Obj *dump) {
     SV *fields_sv = XSBind_cfish_to_perl((cfish_Obj*)fields);
     CHY_UNUSED_VAR(self);
 
-    loaded->doc_id = (int32_t)Cfish_Obj_To_I64(doc_id);
-    loaded->fields  = SvREFCNT_inc(SvRV(fields_sv));
+    lucy_DocIVARS *const loaded_ivars = lucy_Doc_IVARS(loaded);
+    loaded_ivars->doc_id = (int32_t)Cfish_Obj_To_I64(doc_id);
+    loaded_ivars->fields  = SvREFCNT_inc(SvRV(fields_sv));
     SvREFCNT_dec(fields_sv);
 
     return loaded;
@@ -206,21 +215,19 @@ lucy_Doc_load(lucy_Doc *self, cfish_Obj *dump) {
 
 bool
 lucy_Doc_equals(lucy_Doc *self, cfish_Obj *other) {
-    lucy_Doc *twin = (lucy_Doc*)other;
-    HV *my_fields;
-    HV *other_fields;
-    I32 num_fields;
-
-    if (twin == self)                    { return true;  }
+    if ((lucy_Doc*)other  == self)        { return true;  }
     if (!Cfish_Obj_Is_A(other, LUCY_DOC)) { return false; }
-    if (!self->doc_id == twin->doc_id)   { return false; }
-    if (!!self->fields ^ !!twin->fields) { return false; }
+    lucy_DocIVARS *const ivars = lucy_Doc_IVARS(self);
+    lucy_DocIVARS *const ovars = lucy_Doc_IVARS((lucy_Doc*)other);
+
+    if (!ivars->doc_id == ovars->doc_id)   { return false; }
+    if (!!ivars->fields ^ !!ovars->fields) { return false; }
 
     // Verify fields.  Don't allow any deep data structures.
-    my_fields    = (HV*)self->fields;
-    other_fields = (HV*)twin->fields;
+    HV *my_fields    = (HV*)ivars->fields;
+    HV *other_fields = (HV*)ovars->fields;
     if (HvKEYS(my_fields) != HvKEYS(other_fields)) { return false; }
-    num_fields = hv_iterinit(my_fields);
+    I32 num_fields = hv_iterinit(my_fields);
     while (num_fields--) {
         HE *my_entry = hv_iternext(my_fields);
         SV *my_val_sv = HeVAL(my_entry);
@@ -236,7 +243,8 @@ lucy_Doc_equals(lucy_Doc *self, cfish_Obj *other) {
 
 void
 lucy_Doc_destroy(lucy_Doc *self) {
-    if (self->fields) { SvREFCNT_dec((SV*)self->fields); }
+    lucy_DocIVARS *const ivars = lucy_Doc_IVARS(self);
+    if (ivars->fields) { SvREFCNT_dec((SV*)ivars->fields); }
     CFISH_SUPER_DESTROY(self, LUCY_DOC);
 }
 

http://git-wip-us.apache.org/repos/asf/lucy/blob/811358d9/perl/xs/Lucy/Index/DocReader.c
----------------------------------------------------------------------
diff --git a/perl/xs/Lucy/Index/DocReader.c b/perl/xs/Lucy/Index/DocReader.c
index 0c7b2ac..d4e27ae 100644
--- a/perl/xs/Lucy/Index/DocReader.c
+++ b/perl/xs/Lucy/Index/DocReader.c
@@ -29,9 +29,10 @@
 
 lucy_HitDoc*
 lucy_DefDocReader_fetch_doc(lucy_DefaultDocReader *self, int32_t doc_id) {
-    lucy_Schema   *const schema = self->schema;
-    lucy_InStream *const dat_in = self->dat_in;
-    lucy_InStream *const ix_in  = self->ix_in;
+    lucy_DefaultDocReaderIVARS *const ivars = lucy_DefDocReader_IVARS(self);
+    lucy_Schema   *const schema = ivars->schema;
+    lucy_InStream *const dat_in = ivars->dat_in;
+    lucy_InStream *const ix_in  = ivars->ix_in;
     HV *fields = newHV();
     int64_t start;
     uint32_t num_fields;

http://git-wip-us.apache.org/repos/asf/lucy/blob/811358d9/perl/xs/Lucy/Index/Inverter.c
----------------------------------------------------------------------
diff --git a/perl/xs/Lucy/Index/Inverter.c b/perl/xs/Lucy/Index/Inverter.c
index 7f0bc95..d3ad2a8 100644
--- a/perl/xs/Lucy/Index/Inverter.c
+++ b/perl/xs/Lucy/Index/Inverter.c
@@ -30,7 +30,8 @@
 
 static lucy_InverterEntry*
 S_fetch_entry(lucy_Inverter *self, HE *hash_entry) {
-    lucy_Schema *const schema = self->schema;
+    lucy_InverterIVARS *const ivars = lucy_Inverter_IVARS(self);
+    lucy_Schema *const schema = ivars->schema;
     char *key;
     STRLEN key_len;
     STRLEN he_key_len = HeKLEN(hash_entry);
@@ -51,13 +52,13 @@ S_fetch_entry(lucy_Inverter *self, HE *hash_entry) {
 
     cfish_ZombieCharBuf *field = CFISH_ZCB_WRAP_STR(key, key_len);
     int32_t field_num
-        = Lucy_Seg_Field_Num(self->segment, (cfish_CharBuf*)field);
+        = Lucy_Seg_Field_Num(ivars->segment, (cfish_CharBuf*)field);
     if (!field_num) {
         // This field seems not to be in the segment yet.  Try to find it in
         // the Schema.
         if (Lucy_Schema_Fetch_Type(schema, (cfish_CharBuf*)field)) {
             // The field is in the Schema.  Get a field num from the Segment.
-            field_num = Lucy_Seg_Add_Field(self->segment,
+            field_num = Lucy_Seg_Add_Field(ivars->segment,
                                            (cfish_CharBuf*)field);
         }
         else {
@@ -68,10 +69,10 @@ S_fetch_entry(lucy_Inverter *self, HE *hash_entry) {
     }
 
     lucy_InverterEntry *entry
-        = (lucy_InverterEntry*)Cfish_VA_Fetch(self->entry_pool, field_num);
+        = (lucy_InverterEntry*)Cfish_VA_Fetch(ivars->entry_pool, field_num);
     if (!entry) {
         entry = lucy_InvEntry_new(schema, (cfish_CharBuf*)field, field_num);
-        Cfish_VA_Store(self->entry_pool, field_num, (cfish_Obj*)entry);
+        Cfish_VA_Store(ivars->entry_pool, field_num, (cfish_Obj*)entry);
     }
     return entry;
 }
@@ -89,7 +90,9 @@ lucy_Inverter_invert_doc(lucy_Inverter *self, lucy_Doc *doc) {
         HE *hash_entry = hv_iternext(fields);
         lucy_InverterEntry *inv_entry = S_fetch_entry(self, hash_entry);
         SV *value_sv = HeVAL(hash_entry);
-        lucy_FieldType *type = inv_entry->type;
+        lucy_InverterEntryIVARS *const entry_ivars
+            = lucy_InvEntry_IVARS(inv_entry);
+        lucy_FieldType *type = entry_ivars->type;
 
         // Get the field value, forcing text fields to UTF-8.
         switch (Lucy_FType_Primitive_ID(type) & lucy_FType_PRIMITIVE_ID_MASK) {
@@ -97,7 +100,7 @@ lucy_Inverter_invert_doc(lucy_Inverter *self, lucy_Doc *doc) {
                     STRLEN val_len;
                     char *val_ptr = SvPVutf8(value_sv, val_len);
                     cfish_ViewCharBuf *value
-                        = (cfish_ViewCharBuf*)inv_entry->value;
+                        = (cfish_ViewCharBuf*)entry_ivars->value;
                     Cfish_ViewCB_Assign_Str(value, val_ptr, val_len);
                     break;
                 }
@@ -105,17 +108,17 @@ lucy_Inverter_invert_doc(lucy_Inverter *self, lucy_Doc *doc) {
                     STRLEN val_len;
                     char *val_ptr = SvPV(value_sv, val_len);
                     cfish_ViewByteBuf *value
-                        = (cfish_ViewByteBuf*)inv_entry->value;
+                        = (cfish_ViewByteBuf*)entry_ivars->value;
                     Cfish_ViewBB_Assign_Bytes(value, val_ptr, val_len);
                     break;
                 }
             case lucy_FType_INT32: {
-                    cfish_Integer32* value = (cfish_Integer32*)inv_entry->value;
+                    cfish_Integer32* value = (cfish_Integer32*)entry_ivars->value;
                     Cfish_Int32_Set_Value(value, SvIV(value_sv));
                     break;
                 }
             case lucy_FType_INT64: {
-                    cfish_Integer64* value = (cfish_Integer64*)inv_entry->value;
+                    cfish_Integer64* value = (cfish_Integer64*)entry_ivars->value;
                     int64_t val = sizeof(IV) == 8
                                   ? SvIV(value_sv)
                                   : (int64_t)SvNV(value_sv); // lossy
@@ -123,12 +126,12 @@ lucy_Inverter_invert_doc(lucy_Inverter *self, lucy_Doc *doc) {
                     break;
                 }
             case lucy_FType_FLOAT32: {
-                    cfish_Float32* value = (cfish_Float32*)inv_entry->value;
+                    cfish_Float32* value = (cfish_Float32*)entry_ivars->value;
                     Cfish_Float32_Set_Value(value, (float)SvNV(value_sv));
                     break;
                 }
             case lucy_FType_FLOAT64: {
-                    cfish_Float64* value = (cfish_Float64*)inv_entry->value;
+                    cfish_Float64* value = (cfish_Float64*)entry_ivars->value;
                     Cfish_Float64_Set_Value(value, SvNV(value_sv));
                     break;
                 }