lucy-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mar...@apache.org
Subject [lucy-commits] [9/9] git commit: refs/heads/ivars-wip1 - Migrate Perl host code to IVARS.
Date Mon, 01 Jul 2013 16:47:30 GMT
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/6164cdde
Tree: http://git-wip-us.apache.org/repos/asf/lucy/tree/6164cdde
Diff: http://git-wip-us.apache.org/repos/asf/lucy/diff/6164cdde

Branch: refs/heads/ivars-wip1
Commit: 6164cddecf759f330d585ff600a6f4ffa63d908a
Parents: edf18e4
Author: Marvin Humphrey <marvin@rectangular.com>
Authored: Mon Jul 1 08:45:46 2013 -0700
Committer: Marvin Humphrey <marvin@rectangular.com>
Committed: Mon Jul 1 09:06:53 2013 -0700

----------------------------------------------------------------------
 perl/xs/Lucy/Analysis/RegexTokenizer.c | 27 +++++++------
 perl/xs/Lucy/Document/Doc.c            | 60 ++++++++++++++++-------------
 2 files changed, 50 insertions(+), 37 deletions(-)
----------------------------------------------------------------------


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


Mime
View raw message