lucy-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mar...@apache.org
Subject [lucy-commits] [20/34] git commit: refs/heads/master - Migrate LucyX classes to IVARS.
Date Wed, 17 Jul 2013 14:12:40 GMT
Migrate LucyX classes to IVARS.

Change all the LucyX class implementations to access instance vars via an IVARS
struct rather than via `self`.


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

Branch: refs/heads/master
Commit: 5d0cc0985e97fdc6a15274cfe8aa20dd3a71f6e5
Parents: 811358d
Author: Marvin Humphrey <marvin@rectangular.com>
Authored: Mon Jul 1 14:23:39 2013 -0700
Committer: Marvin Humphrey <marvin@rectangular.com>
Committed: Tue Jul 16 16:08:43 2013 -0700

----------------------------------------------------------------------
 core/LucyX/Search/FilterMatcher.c    |  23 +++--
 core/LucyX/Search/MockMatcher.c      |  31 +++---
 core/LucyX/Search/ProximityMatcher.c | 112 ++++++++++++----------
 core/LucyX/Search/ProximityQuery.c   | 152 +++++++++++++++++-------------
 4 files changed, 178 insertions(+), 140 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucy/blob/5d0cc098/core/LucyX/Search/FilterMatcher.c
----------------------------------------------------------------------
diff --git a/core/LucyX/Search/FilterMatcher.c b/core/LucyX/Search/FilterMatcher.c
index a510ca9..cb26c0c 100644
--- a/core/LucyX/Search/FilterMatcher.c
+++ b/core/LucyX/Search/FilterMatcher.c
@@ -28,37 +28,40 @@ FilterMatcher_new(BitVector *bits, int32_t doc_max) {
 FilterMatcher*
 FilterMatcher_init(FilterMatcher *self, BitVector *bits, int32_t doc_max) {
     Matcher_init((Matcher*)self);
+    FilterMatcherIVARS *const ivars = FilterMatcher_IVARS(self);
 
     // Init.
-    self->doc_id       = 0;
+    ivars->doc_id       = 0;
 
     // Assign.
-    self->bits         = (BitVector*)INCREF(bits);
-    self->doc_max      = doc_max;
+    ivars->bits         = (BitVector*)INCREF(bits);
+    ivars->doc_max      = doc_max;
 
     return self;
 }
 
 void
 FilterMatcher_destroy(FilterMatcher *self) {
-    DECREF(self->bits);
+    FilterMatcherIVARS *const ivars = FilterMatcher_IVARS(self);
+    DECREF(ivars->bits);
     SUPER_DESTROY(self, FILTERMATCHER);
 }
 
 int32_t
 FilterMatcher_next(FilterMatcher* self) {
+    FilterMatcherIVARS *const ivars = FilterMatcher_IVARS(self);
     do {
-        if (++self->doc_id > self->doc_max) {
-            self->doc_id--;
+        if (++ivars->doc_id > ivars->doc_max) {
+            ivars->doc_id--;
             return 0;
         }
-    } while (!BitVec_Get(self->bits, self->doc_id));
-    return self->doc_id;
+    } while (!BitVec_Get(ivars->bits, ivars->doc_id));
+    return ivars->doc_id;
 }
 
 int32_t
 FilterMatcher_skip_to(FilterMatcher* self, int32_t target) {
-    self->doc_id = target - 1;
+    FilterMatcher_IVARS(self)->doc_id = target - 1;
     return FilterMatcher_next(self);
 }
 
@@ -70,7 +73,7 @@ FilterMatcher_score(FilterMatcher* self) {
 
 int32_t
 FilterMatcher_get_doc_id(FilterMatcher* self) {
-    return self->doc_id;
+    return FilterMatcher_IVARS(self)->doc_id;
 }
 
 

http://git-wip-us.apache.org/repos/asf/lucy/blob/5d0cc098/core/LucyX/Search/MockMatcher.c
----------------------------------------------------------------------
diff --git a/core/LucyX/Search/MockMatcher.c b/core/LucyX/Search/MockMatcher.c
index 9153cae..c7b77a6 100644
--- a/core/LucyX/Search/MockMatcher.c
+++ b/core/LucyX/Search/MockMatcher.c
@@ -28,41 +28,46 @@ MockMatcher_new(I32Array *doc_ids, ByteBuf *scores) {
 MockMatcher*
 MockMatcher_init(MockMatcher *self, I32Array *doc_ids, ByteBuf *scores) {
     Matcher_init((Matcher*)self);
-    self->tick    = -1;
-    self->size    = I32Arr_Get_Size(doc_ids);
-    self->doc_ids = (I32Array*)INCREF(doc_ids);
-    self->scores  = (ByteBuf*)INCREF(scores);
+    MockMatcherIVARS *const ivars = MockMatcher_IVARS(self);
+    ivars->tick    = -1;
+    ivars->size    = I32Arr_Get_Size(doc_ids);
+    ivars->doc_ids = (I32Array*)INCREF(doc_ids);
+    ivars->scores  = (ByteBuf*)INCREF(scores);
     return self;
 }
 
 void
 MockMatcher_destroy(MockMatcher *self) {
-    DECREF(self->doc_ids);
-    DECREF(self->scores);
+    MockMatcherIVARS *const ivars = MockMatcher_IVARS(self);
+    DECREF(ivars->doc_ids);
+    DECREF(ivars->scores);
     SUPER_DESTROY(self, MOCKMATCHER);
 }
 
 int32_t
 MockMatcher_next(MockMatcher* self) {
-    if (++self->tick >= (int32_t)self->size) {
-        self->tick--;
+    MockMatcherIVARS *const ivars = MockMatcher_IVARS(self);
+    if (++ivars->tick >= (int32_t)ivars->size) {
+        ivars->tick--;
         return 0;
     }
-    return I32Arr_Get(self->doc_ids, self->tick);
+    return I32Arr_Get(ivars->doc_ids, ivars->tick);
 }
 
 float
 MockMatcher_score(MockMatcher* self) {
-    if (!self->scores) {
+    MockMatcherIVARS *const ivars = MockMatcher_IVARS(self);
+    if (!ivars->scores) {
         THROW(ERR, "Can't call Score() unless scores supplied");
     }
-    float *raw_scores = (float*)BB_Get_Buf(self->scores);
-    return raw_scores[self->tick];
+    float *raw_scores = (float*)BB_Get_Buf(ivars->scores);
+    return raw_scores[ivars->tick];
 }
 
 int32_t
 MockMatcher_get_doc_id(MockMatcher* self) {
-    return I32Arr_Get(self->doc_ids, self->tick);
+    MockMatcherIVARS *const ivars = MockMatcher_IVARS(self);
+    return I32Arr_Get(ivars->doc_ids, ivars->tick);
 }
 
 

http://git-wip-us.apache.org/repos/asf/lucy/blob/5d0cc098/core/LucyX/Search/ProximityMatcher.c
----------------------------------------------------------------------
diff --git a/core/LucyX/Search/ProximityMatcher.c b/core/LucyX/Search/ProximityMatcher.c
index c7cc495..9918620 100644
--- a/core/LucyX/Search/ProximityMatcher.c
+++ b/core/LucyX/Search/ProximityMatcher.c
@@ -39,57 +39,60 @@ ProximityMatcher*
 ProximityMatcher_init(ProximityMatcher *self, Similarity *similarity,
                       VArray *plists, Compiler *compiler, uint32_t within) {
     Matcher_init((Matcher*)self);
+    ProximityMatcherIVARS *const ivars = ProximityMatcher_IVARS(self);
 
     // Init.
-    self->anchor_set       = BB_new(0);
-    self->proximity_freq   = 0.0;
-    self->proximity_boost  = 0.0;
-    self->first_time       = true;
-    self->more             = true;
-    self->within           = within;
+    ivars->anchor_set       = BB_new(0);
+    ivars->proximity_freq   = 0.0;
+    ivars->proximity_boost  = 0.0;
+    ivars->first_time       = true;
+    ivars->more             = true;
+    ivars->within           = within;
 
     // Extract PostingLists out of VArray into local C array for quick access.
-    self->num_elements = VA_Get_Size(plists);
-    self->plists = (PostingList**)MALLOCATE(
-                       self->num_elements * sizeof(PostingList*));
-    for (size_t i = 0; i < self->num_elements; i++) {
+    ivars->num_elements = VA_Get_Size(plists);
+    ivars->plists = (PostingList**)MALLOCATE(
+                       ivars->num_elements * sizeof(PostingList*));
+    for (size_t i = 0; i < ivars->num_elements; i++) {
         PostingList *const plist
             = (PostingList*)CERTIFY(VA_Fetch(plists, i), POSTINGLIST);
         if (plist == NULL) {
             THROW(ERR, "Missing element %u32", i);
         }
-        self->plists[i] = (PostingList*)INCREF(plist);
+        ivars->plists[i] = (PostingList*)INCREF(plist);
     }
 
     // Assign.
-    self->sim       = (Similarity*)INCREF(similarity);
-    self->compiler  = (Compiler*)INCREF(compiler);
-    self->weight    = Compiler_Get_Weight(compiler);
+    ivars->sim       = (Similarity*)INCREF(similarity);
+    ivars->compiler  = (Compiler*)INCREF(compiler);
+    ivars->weight    = Compiler_Get_Weight(compiler);
 
     return self;
 }
 
 void
 ProximityMatcher_destroy(ProximityMatcher *self) {
-    if (self->plists) {
-        for (size_t i = 0; i < self->num_elements; i++) {
-            DECREF(self->plists[i]);
+    ProximityMatcherIVARS *const ivars = ProximityMatcher_IVARS(self);
+    if (ivars->plists) {
+        for (size_t i = 0; i < ivars->num_elements; i++) {
+            DECREF(ivars->plists[i]);
         }
-        FREEMEM(self->plists);
+        FREEMEM(ivars->plists);
     }
-    DECREF(self->sim);
-    DECREF(self->anchor_set);
-    DECREF(self->compiler);
+    DECREF(ivars->sim);
+    DECREF(ivars->anchor_set);
+    DECREF(ivars->compiler);
     SUPER_DESTROY(self, PROXIMITYMATCHER);
 }
 
 int32_t
 ProximityMatcher_next(ProximityMatcher *self) {
-    if (self->first_time) {
+    ProximityMatcherIVARS *const ivars = ProximityMatcher_IVARS(self);
+    if (ivars->first_time) {
         return ProximityMatcher_Advance(self, 1);
     }
-    else if (self->more) {
-        const int32_t target = PList_Get_Doc_ID(self->plists[0]) + 1;
+    else if (ivars->more) {
+        const int32_t target = PList_Get_Doc_ID(ivars->plists[0]) + 1;
         return ProximityMatcher_Advance(self, target);
     }
     else {
@@ -99,25 +102,26 @@ ProximityMatcher_next(ProximityMatcher *self) {
 
 int32_t
 ProximityMatcher_advance(ProximityMatcher *self, int32_t target) {
-    PostingList **const plists       = self->plists;
-    const uint32_t      num_elements = self->num_elements;
+    ProximityMatcherIVARS *const ivars = ProximityMatcher_IVARS(self);
+    PostingList **const plists       = ivars->plists;
+    const uint32_t      num_elements = ivars->num_elements;
     int32_t             highest      = 0;
 
     // Reset match variables to indicate no match.  New values will be
     // assigned if a match succeeds.
-    self->proximity_freq = 0.0;
-    self->doc_id         = 0;
+    ivars->proximity_freq = 0.0;
+    ivars->doc_id         = 0;
 
     // Find the lowest possible matching doc ID greater than the current doc
     // ID.  If any one of the PostingLists is exhausted, we're done.
-    if (self->first_time) {
-        self->first_time = false;
+    if (ivars->first_time) {
+        ivars->first_time = false;
 
         // On the first call to Advance(), advance all PostingLists.
-        for (size_t i = 0, max = self->num_elements; i < max; i++) {
+        for (size_t i = 0, max = ivars->num_elements; i < max; i++) {
             int32_t candidate = PList_Advance(plists[i], target);
             if (!candidate) {
-                self->more = false;
+                ivars->more = false;
                 return 0;
             }
             else if (candidate > highest) {
@@ -131,7 +135,7 @@ ProximityMatcher_advance(ProximityMatcher *self, int32_t target) {
         // becomes the minimum target which all the others must move up to.
         highest = PList_Advance(plists[0], target);
         if (highest == 0) {
-            self->more = false;
+            ivars->more = false;
             return 0;
         }
     }
@@ -156,7 +160,7 @@ ProximityMatcher_advance(ProximityMatcher *self, int32_t target) {
 
                 // If this PostingList is exhausted, we're done.
                 if (candidate == 0) {
-                    self->more = false;
+                    ivars->more = false;
                     return 0;
                 }
 
@@ -178,14 +182,14 @@ ProximityMatcher_advance(ProximityMatcher *self, int32_t target) {
         // If we've found a doc with all terms in it, see if they form a
         // phrase.
         if (agreement && highest >= target) {
-            self->proximity_freq = ProximityMatcher_Calc_Proximity_Freq(self);
-            if (self->proximity_freq == 0.0) {
+            ivars->proximity_freq = ProximityMatcher_Calc_Proximity_Freq(self);
+            if (ivars->proximity_freq == 0.0) {
                 // No phrase.  Move on to another doc.
                 target += 1;
             }
             else {
                 // Success!
-                self->doc_id = highest;
+                ivars->doc_id = highest;
                 return highest;
             }
         }
@@ -246,7 +250,8 @@ DONE:
 
 float
 ProximityMatcher_calc_proximity_freq(ProximityMatcher *self) {
-    PostingList **const plists   = self->plists;
+    ProximityMatcherIVARS *const ivars = ProximityMatcher_IVARS(self);
+    PostingList **const plists = ivars->plists;
 
     /* Create a overwriteable "anchor set" from the first posting.
      *
@@ -268,25 +273,27 @@ ProximityMatcher_calc_proximity_freq(ProximityMatcher *self) {
      * is our proximity freq.
      */
     ScorePosting *posting = (ScorePosting*)PList_Get_Posting(plists[0]);
-    uint32_t anchors_remaining = posting->freq;
+    ScorePostingIVARS *const post_ivars = ScorePost_IVARS(posting);
+    uint32_t anchors_remaining = post_ivars->freq;
     if (!anchors_remaining) { return 0.0f; }
 
     size_t    amount        = anchors_remaining * sizeof(uint32_t);
-    uint32_t *anchors_start = (uint32_t*)BB_Grow(self->anchor_set, amount);
+    uint32_t *anchors_start = (uint32_t*)BB_Grow(ivars->anchor_set, amount);
     uint32_t *anchors_end   = anchors_start + anchors_remaining;
-    memcpy(anchors_start, posting->prox, amount);
+    memcpy(anchors_start, post_ivars->prox, amount);
 
     // Match the positions of other terms against the anchor set.
-    for (uint32_t i = 1, max = self->num_elements; i < max; i++) {
+    for (uint32_t i = 1, max = ivars->num_elements; i < max; i++) {
         // Get the array of positions for the next term.  Unlike the anchor
         // set (which is a copy), these won't be overwritten.
-        ScorePosting *posting = (ScorePosting*)PList_Get_Posting(plists[i]);
-        uint32_t *candidates_start = posting->prox;
-        uint32_t *candidates_end   = candidates_start + posting->freq;
+        ScorePosting *next_post = (ScorePosting*)PList_Get_Posting(plists[i]);
+        ScorePostingIVARS *const next_post_ivars = ScorePost_IVARS(next_post);
+        uint32_t *candidates_start = next_post_ivars->prox;
+        uint32_t *candidates_end   = candidates_start + next_post_ivars->freq;
 
         // Splice out anchors that don't match the next term.  Bail out if
         // we've eliminated all possible anchors.
-        if (self->within == 1) { // exact phrase match
+        if (ivars->within == 1) { // exact phrase match
             anchors_remaining = SI_winnow_anchors(anchors_start, anchors_end,
                                                   candidates_start,
                                                   candidates_end, i, 1);
@@ -295,7 +302,7 @@ ProximityMatcher_calc_proximity_freq(ProximityMatcher *self) {
             anchors_remaining = SI_winnow_anchors(anchors_start, anchors_end,
                                                   candidates_start,
                                                   candidates_end, i,
-                                                  self->within);
+                                                  ivars->within);
         }
         if (!anchors_remaining) { return 0.0f; }
 
@@ -309,15 +316,16 @@ ProximityMatcher_calc_proximity_freq(ProximityMatcher *self) {
 
 int32_t
 ProximityMatcher_get_doc_id(ProximityMatcher *self) {
-    return self->doc_id;
+    return ProximityMatcher_IVARS(self)->doc_id;
 }
 
 float
 ProximityMatcher_score(ProximityMatcher *self) {
-    ScorePosting *posting = (ScorePosting*)PList_Get_Posting(self->plists[0]);
-    float score = Sim_TF(self->sim, self->proximity_freq)
-                  * self->weight
-                  * posting->weight;
+    ProximityMatcherIVARS *const ivars = ProximityMatcher_IVARS(self);
+    ScorePosting *posting = (ScorePosting*)PList_Get_Posting(ivars->plists[0]);
+    float score = Sim_TF(ivars->sim, ivars->proximity_freq)
+                  * ivars->weight
+                  * ScorePost_IVARS(posting)->weight;
     return score;
 }
 

http://git-wip-us.apache.org/repos/asf/lucy/blob/5d0cc098/core/LucyX/Search/ProximityQuery.c
----------------------------------------------------------------------
diff --git a/core/LucyX/Search/ProximityQuery.c b/core/LucyX/Search/ProximityQuery.c
index 7cd5bdc..3e8a435 100644
--- a/core/LucyX/Search/ProximityQuery.c
+++ b/core/LucyX/Search/ProximityQuery.c
@@ -58,8 +58,9 @@ ProximityQuery_init(ProximityQuery *self, const CharBuf *field, VArray *terms,
 
 void
 ProximityQuery_destroy(ProximityQuery *self) {
-    DECREF(self->terms);
-    DECREF(self->field);
+    ProximityQueryIVARS *const ivars = ProximityQuery_IVARS(self);
+    DECREF(ivars->terms);
+    DECREF(ivars->field);
     SUPER_DESTROY(self, PROXIMITYQUERY);
 }
 
@@ -67,21 +68,23 @@ static ProximityQuery*
 S_do_init(ProximityQuery *self, CharBuf *field, VArray *terms, float boost,
           uint32_t within) {
     Query_init((Query*)self, boost);
+    ProximityQueryIVARS *const ivars = ProximityQuery_IVARS(self);
     for (uint32_t i = 0, max = VA_Get_Size(terms); i < max; i++) {
         CERTIFY(VA_Fetch(terms, i), OBJ);
     }
-    self->field  = field;
-    self->terms  = terms;
-    self->within = within;
+    ivars->field  = field;
+    ivars->terms  = terms;
+    ivars->within = within;
     return self;
 }
 
 void
 ProximityQuery_serialize(ProximityQuery *self, OutStream *outstream) {
-    OutStream_Write_F32(outstream, self->boost);
-    Freezer_serialize_charbuf(self->field, outstream);
-    Freezer_serialize_varray(self->terms, outstream);
-    OutStream_Write_C32(outstream, self->within);
+    ProximityQueryIVARS *const ivars = ProximityQuery_IVARS(self);
+    OutStream_Write_F32(outstream, ivars->boost);
+    Freezer_serialize_charbuf(ivars->field, outstream);
+    Freezer_serialize_varray(ivars->terms, outstream);
+    OutStream_Write_C32(outstream, ivars->within);
 }
 
 ProximityQuery*
@@ -95,27 +98,31 @@ ProximityQuery_deserialize(ProximityQuery *self, InStream *instream) {
 
 bool
 ProximityQuery_equals(ProximityQuery *self, Obj *other) {
-    ProximityQuery *twin = (ProximityQuery*)other;
-    if (twin == self)                     { return true; }
+    if ((ProximityQuery*)other == self)   { return true; }
     if (!Obj_Is_A(other, PROXIMITYQUERY)) { return false; }
-    if (self->boost != twin->boost)       { return false; }
-    if (self->field && !twin->field)      { return false; }
-    if (!self->field && twin->field)      { return false; }
-    if (self->field && !CB_Equals(self->field, (Obj*)twin->field)) {
+    ProximityQueryIVARS *const ivars = ProximityQuery_IVARS(self);
+    ProximityQueryIVARS *const ovars
+        = ProximityQuery_IVARS((ProximityQuery*)other);
+
+    if (ivars->boost != ovars->boost)       { return false; }
+    if (ivars->field && !ovars->field)      { return false; }
+    if (!ivars->field && ovars->field)      { return false; }
+    if (ivars->field && !CB_Equals(ivars->field, (Obj*)ovars->field)) {
         return false;
     }
-    if (!VA_Equals(twin->terms, (Obj*)self->terms)) { return false; }
-    if (self->within != twin->within)               { return false; }
+    if (!VA_Equals(ovars->terms, (Obj*)ivars->terms)) { return false; }
+    if (ivars->within != ovars->within)               { return false; }
     return true;
 }
 
 CharBuf*
 ProximityQuery_to_string(ProximityQuery *self) {
-    uint32_t num_terms = VA_Get_Size(self->terms);
-    CharBuf *retval = CB_Clone(self->field);
+    ProximityQueryIVARS *const ivars = ProximityQuery_IVARS(self);
+    uint32_t num_terms = VA_Get_Size(ivars->terms);
+    CharBuf *retval = CB_Clone(ivars->field);
     CB_Cat_Trusted_Str(retval, ":\"", 2);
     for (uint32_t i = 0; i < num_terms; i++) {
-        Obj *term = VA_Fetch(self->terms, i);
+        Obj *term = VA_Fetch(ivars->terms, i);
         CharBuf *term_string = Obj_To_String(term);
         CB_Cat(retval, term_string);
         DECREF(term_string);
@@ -124,18 +131,19 @@ ProximityQuery_to_string(ProximityQuery *self) {
         }
     }
     CB_Cat_Trusted_Str(retval, "\"", 1);
-    CB_catf(retval, "~%u32", self->within);
+    CB_catf(retval, "~%u32", ivars->within);
     return retval;
 }
 
 Compiler*
 ProximityQuery_make_compiler(ProximityQuery *self, Searcher *searcher,
                              float boost, bool subordinate) {
-    if (VA_Get_Size(self->terms) == 1) {
+    ProximityQueryIVARS *const ivars = ProximityQuery_IVARS(self);
+    if (VA_Get_Size(ivars->terms) == 1) {
         // Optimize for one-term "phrases".
-        Obj *term = VA_Fetch(self->terms, 0);
-        TermQuery *term_query = TermQuery_new(self->field, term);
-        TermQuery_Set_Boost(term_query, self->boost);
+        Obj *term = VA_Fetch(ivars->terms, 0);
+        TermQuery *term_query = TermQuery_new(ivars->field, term);
+        TermQuery_Set_Boost(term_query, ivars->boost);
         TermCompiler *term_compiler
             = (TermCompiler*)TermQuery_Make_Compiler(term_query, searcher,
                                                      boost, subordinate);
@@ -144,7 +152,7 @@ ProximityQuery_make_compiler(ProximityQuery *self, Searcher *searcher,
     }
     else {
         ProximityCompiler *compiler
-            = ProximityCompiler_new(self, searcher, boost, self->within);
+            = ProximityCompiler_new(self, searcher, boost, ivars->within);
         if (!subordinate) {
             ProximityCompiler_Normalize(compiler);
         }
@@ -154,17 +162,17 @@ ProximityQuery_make_compiler(ProximityQuery *self, Searcher *searcher,
 
 CharBuf*
 ProximityQuery_get_field(ProximityQuery *self) {
-    return self->field;
+    return ProximityQuery_IVARS(self)->field;
 }
 
 VArray*
 ProximityQuery_get_terms(ProximityQuery *self) {
-    return self->terms;
+    return ProximityQuery_IVARS(self)->terms;
 }
 
 uint32_t
 ProximityQuery_get_within(ProximityQuery  *self) {
-    return self->within;
+    return ProximityQuery_IVARS(self)->within;
 }
 
 /*********************************************************************/
@@ -180,11 +188,13 @@ ProximityCompiler_new(ProximityQuery *parent, Searcher *searcher, float
boost,
 ProximityCompiler*
 ProximityCompiler_init(ProximityCompiler *self, ProximityQuery *parent,
                        Searcher *searcher, float boost, uint32_t within) {
+    ProximityCompilerIVARS *const ivars = ProximityCompiler_IVARS(self);
+    ProximityQueryIVARS *const parent_ivars = ProximityQuery_IVARS(parent);
     Schema     *schema = Searcher_Get_Schema(searcher);
-    Similarity *sim    = Schema_Fetch_Sim(schema, parent->field);
-    VArray     *terms  = parent->terms;
+    Similarity *sim    = Schema_Fetch_Sim(schema, parent_ivars->field);
+    VArray     *terms  = parent_ivars->terms;
 
-    self->within = within;
+    ivars->within = within;
 
     // Try harder to find a Similarity if necessary.
     if (!sim) { sim = Schema_Get_Similarity(schema); }
@@ -193,16 +203,17 @@ ProximityCompiler_init(ProximityCompiler *self, ProximityQuery *parent,
     Compiler_init((Compiler*)self, (Query*)parent, searcher, sim, boost);
 
     // Store IDF for the phrase.
-    self->idf = 0;
+    ivars->idf = 0;
     for (uint32_t i = 0, max = VA_Get_Size(terms); i < max; i++) {
         Obj *term = VA_Fetch(terms, i);
         int32_t doc_max  = Searcher_Doc_Max(searcher);
-        int32_t doc_freq = Searcher_Doc_Freq(searcher, parent->field, term);
-        self->idf += Sim_IDF(sim, doc_freq, doc_max);
+        int32_t doc_freq
+            = Searcher_Doc_Freq(searcher, parent_ivars->field,term);
+        ivars->idf += Sim_IDF(sim, doc_freq, doc_max);
     }
 
     // Calculate raw weight.
-    self->raw_weight = self->idf * self->boost;
+    ivars->raw_weight = ivars->idf * ivars->boost;
 
     return self;
 }
@@ -212,11 +223,12 @@ ProximityCompiler_serialize(ProximityCompiler *self, OutStream *outstream)
{
     ProximityCompiler_Serialize_t super_serialize
             = SUPER_METHOD_PTR(PROXIMITYCOMPILER, Lucy_ProximityCompiler_Serialize);
     super_serialize(self, outstream);
-    OutStream_Write_F32(outstream, self->idf);
-    OutStream_Write_F32(outstream, self->raw_weight);
-    OutStream_Write_F32(outstream, self->query_norm_factor);
-    OutStream_Write_F32(outstream, self->normalized_weight);
-    OutStream_Write_C32(outstream, self->within);
+    ProximityCompilerIVARS *const ivars = ProximityCompiler_IVARS(self);
+    OutStream_Write_F32(outstream, ivars->idf);
+    OutStream_Write_F32(outstream, ivars->raw_weight);
+    OutStream_Write_F32(outstream, ivars->query_norm_factor);
+    OutStream_Write_F32(outstream, ivars->normalized_weight);
+    OutStream_Write_C32(outstream, ivars->within);
 }
 
 ProximityCompiler*
@@ -224,49 +236,57 @@ ProximityCompiler_deserialize(ProximityCompiler *self, InStream *instream)
{
     ProximityCompiler_Deserialize_t super_deserialize
             = SUPER_METHOD_PTR(PROXIMITYCOMPILER, Lucy_ProximityCompiler_Deserialize);
     self = super_deserialize(self, instream);
-    self->idf               = InStream_Read_F32(instream);
-    self->raw_weight        = InStream_Read_F32(instream);
-    self->query_norm_factor = InStream_Read_F32(instream);
-    self->normalized_weight = InStream_Read_F32(instream);
-    self->within            = InStream_Read_C32(instream);
+    ProximityCompilerIVARS *const ivars = ProximityCompiler_IVARS(self);
+    ivars->idf               = InStream_Read_F32(instream);
+    ivars->raw_weight        = InStream_Read_F32(instream);
+    ivars->query_norm_factor = InStream_Read_F32(instream);
+    ivars->normalized_weight = InStream_Read_F32(instream);
+    ivars->within            = InStream_Read_C32(instream);
     return self;
 }
 
 bool
 ProximityCompiler_equals(ProximityCompiler *self, Obj *other) {
-    ProximityCompiler *twin = (ProximityCompiler*)other;
-    if (!Obj_Is_A(other, PROXIMITYCOMPILER))                { return false; }
-    if (!Compiler_equals((Compiler*)self, other))           { return false; }
-    if (self->idf != twin->idf)                             { return false; }
-    if (self->raw_weight != twin->raw_weight)               { return false; }
-    if (self->query_norm_factor != twin->query_norm_factor) { return false; }
-    if (self->normalized_weight != twin->normalized_weight) { return false; }
-    if (self->within            != twin->within)            { return false; }
+    if ((ProximityCompiler*)other == self)        { return true; }
+    if (!Obj_Is_A(other, PROXIMITYCOMPILER))      { return false; }
+    if (!Compiler_equals((Compiler*)self, other)) { return false; }
+    ProximityCompilerIVARS *const ivars = ProximityCompiler_IVARS(self);
+    ProximityCompilerIVARS *const ovars
+        = ProximityCompiler_IVARS((ProximityCompiler*)other);
+    if (ivars->idf != ovars->idf)                             { return false; }
+    if (ivars->raw_weight != ovars->raw_weight)               { return false; }
+    if (ivars->query_norm_factor != ovars->query_norm_factor) { return false; }
+    if (ivars->normalized_weight != ovars->normalized_weight) { return false; }
+    if (ivars->within            != ovars->within)            { return false; }
     return true;
 }
 
 float
 ProximityCompiler_get_weight(ProximityCompiler *self) {
-    return self->normalized_weight;
+    return ProximityCompiler_IVARS(self)->normalized_weight;
 }
 
 float
 ProximityCompiler_sum_of_squared_weights(ProximityCompiler *self) {
-    return self->raw_weight * self->raw_weight;
+    ProximityCompilerIVARS *const ivars = ProximityCompiler_IVARS(self);
+    return ivars->raw_weight * ivars->raw_weight;
 }
 
 void
 ProximityCompiler_apply_norm_factor(ProximityCompiler *self, float factor) {
-    self->query_norm_factor = factor;
-    self->normalized_weight = self->raw_weight * self->idf * factor;
+    ProximityCompilerIVARS *const ivars = ProximityCompiler_IVARS(self);
+    ivars->query_norm_factor = factor;
+    ivars->normalized_weight = ivars->raw_weight * ivars->idf * factor;
 }
 
 Matcher*
 ProximityCompiler_make_matcher(ProximityCompiler *self, SegReader *reader,
                                bool need_score) {
+    ProximityCompilerIVARS *const ivars = ProximityCompiler_IVARS(self);
     UNUSED_VAR(need_score);
-    ProximityQuery *const parent = (ProximityQuery*)self->parent;
-    VArray *const      terms     = parent->terms;
+    ProximityQueryIVARS *const parent_ivars
+        = ProximityQuery_IVARS((ProximityQuery*)ivars->parent);
+    VArray *const      terms     = parent_ivars->terms;
     uint32_t           num_terms = VA_Get_Size(terms);
 
     // Bail if there are no terms.
@@ -292,7 +312,7 @@ ProximityCompiler_make_matcher(ProximityCompiler *self, SegReader *reader,
     for (uint32_t i = 0; i < num_terms; i++) {
         Obj *term = VA_Fetch(terms, i);
         PostingList *plist
-            = PListReader_Posting_List(plist_reader, parent->field, term);
+            = PListReader_Posting_List(plist_reader, parent_ivars->field, term);
 
         // Bail if any one of the terms isn't in the index.
         if (!plist || !PList_Get_Doc_Freq(plist)) {
@@ -304,7 +324,7 @@ ProximityCompiler_make_matcher(ProximityCompiler *self, SegReader *reader,
     }
 
     Matcher *retval
-        = (Matcher*)ProximityMatcher_new(sim, plists, (Compiler*)self, self->within);
+        = (Matcher*)ProximityMatcher_new(sim, plists, (Compiler*)self, ivars->within);
     DECREF(plists);
     return retval;
 }
@@ -312,15 +332,17 @@ ProximityCompiler_make_matcher(ProximityCompiler *self, SegReader *reader,
 VArray*
 ProximityCompiler_highlight_spans(ProximityCompiler *self, Searcher *searcher,
                                   DocVector *doc_vec, const CharBuf *field) {
-    ProximityQuery *const parent = (ProximityQuery*)self->parent;
-    VArray         *const terms  = parent->terms;
+    ProximityCompilerIVARS *const ivars = ProximityCompiler_IVARS(self);
+    ProximityQueryIVARS *const parent_ivars
+        = ProximityQuery_IVARS((ProximityQuery*)ivars->parent);
+    VArray         *const terms  = parent_ivars->terms;
     VArray         *const spans  = VA_new(0);
     const uint32_t  num_terms    = VA_Get_Size(terms);
     UNUSED_VAR(searcher);
 
     // Bail if no terms or field doesn't match.
     if (!num_terms) { return spans; }
-    if (!CB_Equals(field, (Obj*)parent->field)) { return spans; }
+    if (!CB_Equals(field, (Obj*)parent_ivars->field)) { return spans; }
 
     VArray      *term_vectors    = VA_new(num_terms);
     BitVector   *posit_vec       = BitVec_new(0);


Mime
View raw message