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

[lucy-commits] [22/34] git commit: refs/heads/master - Migrate Lucy's posting classes to IVARS.

Migrate Lucy's posting classes to IVARS.

Change all of Lucy's posting classes 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/14e863fb
Tree: http://git-wip-us.apache.org/repos/asf/lucy/tree/14e863fb
Diff: http://git-wip-us.apache.org/repos/asf/lucy/diff/14e863fb

Branch: refs/heads/master
Commit: 14e863fb64d05f441e086074a620f94a1d9cd5ae
Parents: 965fdb2
Author: Marvin Humphrey <ma...@rectangular.com>
Authored: Sun Jun 30 20:34:50 2013 -0700
Committer: Marvin Humphrey <ma...@rectangular.com>
Committed: Tue Jul 16 16:08:43 2013 -0700

----------------------------------------------------------------------
 core/Lucy/Index/Posting/MatchPosting.c | 127 ++++++++++++++++------------
 core/Lucy/Index/Posting/RawPosting.c   |  48 ++++++-----
 core/Lucy/Index/Posting/RichPosting.c  |  69 ++++++++-------
 core/Lucy/Index/Posting/ScorePosting.c |  98 ++++++++++++---------
 4 files changed, 199 insertions(+), 143 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucy/blob/14e863fb/core/Lucy/Index/Posting/MatchPosting.c
----------------------------------------------------------------------
diff --git a/core/Lucy/Index/Posting/MatchPosting.c b/core/Lucy/Index/Posting/MatchPosting.c
index 3ff887f..bdb9f97 100644
--- a/core/Lucy/Index/Posting/MatchPosting.c
+++ b/core/Lucy/Index/Posting/MatchPosting.c
@@ -43,8 +43,8 @@
 #include "Lucy/Store/OutStream.h"
 #include "Lucy/Util/MemoryPool.h"
 
-#define MAX_RAW_POSTING_LEN(_text_len) \
-    (              sizeof(RawPosting) \
+#define MAX_RAW_POSTING_LEN(_raw_post_size, _text_len) \
+    (              _raw_post_size \
                    + _text_len + 1            /* term text content */ \
     )
 
@@ -56,38 +56,41 @@ MatchPost_new(Similarity *sim) {
 
 MatchPosting*
 MatchPost_init(MatchPosting *self, Similarity *sim) {
-    self->sim = (Similarity*)INCREF(sim);
+    MatchPostingIVARS *const ivars = MatchPost_IVARS(self);
+    ivars->sim = (Similarity*)INCREF(sim);
     return (MatchPosting*)Post_init((Posting*)self);
 }
 
 void
 MatchPost_destroy(MatchPosting *self) {
-    DECREF(self->sim);
+    MatchPostingIVARS *const ivars = MatchPost_IVARS(self);
+    DECREF(ivars->sim);
     SUPER_DESTROY(self, MATCHPOSTING);
 }
 
 int32_t
 MatchPost_get_freq(MatchPosting *self) {
-    return self->freq;
+    return MatchPost_IVARS(self)->freq;
 }
 
 void
 MatchPost_reset(MatchPosting *self) {
-    self->doc_id = 0;
+    MatchPost_IVARS(self)->doc_id = 0;
 }
 
 void
 MatchPost_read_record(MatchPosting *self, InStream *instream) {
+    MatchPostingIVARS *const ivars = MatchPost_IVARS(self);
     const uint32_t doc_code = InStream_Read_C32(instream);
     const uint32_t doc_delta = doc_code >> 1;
 
     // Apply delta doc and retrieve freq.
-    self->doc_id   += doc_delta;
+    ivars->doc_id   += doc_delta;
     if (doc_code & 1) {
-        self->freq = 1;
+        ivars->freq = 1;
     }
     else {
-        self->freq = InStream_Read_C32(instream);
+        ivars->freq = InStream_Read_C32(instream);
     }
 }
 
@@ -102,7 +105,8 @@ MatchPost_read_raw(MatchPosting *self, InStream *instream, int32_t last_doc_id,
     const uint32_t freq      = (doc_code & 1)
                                ? 1
                                : InStream_Read_C32(instream);
-    size_t raw_post_bytes    = MAX_RAW_POSTING_LEN(text_size);
+    const size_t base_size    = VTable_Get_Obj_Alloc_Size(RAWPOSTING);
+    size_t raw_post_bytes    = MAX_RAW_POSTING_LEN(base_size, text_size);
     void *const allocation   = MemPool_Grab(mem_pool, raw_post_bytes);
     UNUSED_VAR(self);
 
@@ -115,6 +119,7 @@ MatchPost_add_inversion_to_pool(MatchPosting *self, PostingPool *post_pool,
                                 int32_t doc_id, float doc_boost,
                                 float length_norm) {
     MemoryPool  *mem_pool = PostPool_Get_Mem_Pool(post_pool);
+    const size_t base_size = VTable_Get_Obj_Alloc_Size(RAWPOSTING);
     Token      **tokens;
     uint32_t     freq;
 
@@ -125,11 +130,12 @@ MatchPost_add_inversion_to_pool(MatchPosting *self, PostingPool *post_pool,
 
     Inversion_Reset(inversion);
     while ((tokens = Inversion_Next_Cluster(inversion, &freq)) != NULL) {
-        Token   *token          = *tokens;
-        uint32_t raw_post_bytes = MAX_RAW_POSTING_LEN(token->len);
+        TokenIVARS *const token_ivars = Token_IVARS(*tokens);
+        uint32_t raw_post_bytes
+            = MAX_RAW_POSTING_LEN(base_size, token_ivars->len);
         RawPosting *raw_posting
             = RawPost_new(MemPool_Grab(mem_pool, raw_post_bytes), doc_id,
-                          freq, token->text, token->len);
+                          freq, token_ivars->text, token_ivars->len);
         PostPool_Feed(post_pool, &raw_posting);
     }
 }
@@ -156,7 +162,7 @@ MatchPostMatcher_init(MatchPostingMatcher *self, Similarity *sim,
 
 float
 MatchPostMatcher_score(MatchPostingMatcher* self) {
-    return self->weight;
+    return MatchPostMatcher_IVARS(self)->weight;
 }
 
 /***************************************************************************/
@@ -179,46 +185,55 @@ MatchPostWriter_init(MatchPostingWriter *self, Schema *schema,
         = CB_newf("%o/postings-%i32.dat", Seg_Get_Name(segment), field_num);
     PostWriter_init((PostingWriter*)self, schema, snapshot, segment,
                     polyreader, field_num);
-    self->outstream = Folder_Open_Out(folder, filename);
-    if (!self->outstream) { RETHROW(INCREF(Err_get_error())); }
+    MatchPostingWriterIVARS *const ivars = MatchPostWriter_IVARS(self);
+    ivars->outstream = Folder_Open_Out(folder, filename);
+    if (!ivars->outstream) { RETHROW(INCREF(Err_get_error())); }
     DECREF(filename);
     return self;
 }
 
 void
 MatchPostWriter_destroy(MatchPostingWriter *self) {
-    DECREF(self->outstream);
+    MatchPostingWriterIVARS *const ivars = MatchPostWriter_IVARS(self);
+    DECREF(ivars->outstream);
     SUPER_DESTROY(self, MATCHPOSTINGWRITER);
 }
 
 void
 MatchPostWriter_write_posting(MatchPostingWriter *self, RawPosting *posting) {
-    OutStream *const outstream   = self->outstream;
-    const int32_t    doc_id      = posting->doc_id;
-    const uint32_t   delta_doc   = doc_id - self->last_doc_id;
-    char  *const     aux_content = posting->blob + posting->content_len;
-    if (posting->freq == 1) {
+    MatchPostingWriterIVARS *const ivars = MatchPostWriter_IVARS(self);
+    RawPostingIVARS *const posting_ivars = RawPost_IVARS(posting);
+    OutStream *const outstream   = ivars->outstream;
+    const int32_t    doc_id      = posting_ivars->doc_id;
+    const uint32_t   delta_doc   = doc_id - ivars->last_doc_id;
+    char  *const     aux_content = posting_ivars->blob
+                                   + posting_ivars->content_len;
+    if (posting_ivars->freq == 1) {
         const uint32_t doc_code = (delta_doc << 1) | 1;
         OutStream_Write_C32(outstream, doc_code);
     }
     else {
         const uint32_t doc_code = delta_doc << 1;
         OutStream_Write_C32(outstream, doc_code);
-        OutStream_Write_C32(outstream, posting->freq);
+        OutStream_Write_C32(outstream, posting_ivars->freq);
     }
-    OutStream_Write_Bytes(outstream, aux_content, posting->aux_len);
-    self->last_doc_id = doc_id;
+    OutStream_Write_Bytes(outstream, aux_content, posting_ivars->aux_len);
+    ivars->last_doc_id = doc_id;
 }
 
 void
 MatchPostWriter_start_term(MatchPostingWriter *self, TermInfo *tinfo) {
-    self->last_doc_id   = 0;
-    tinfo->post_filepos = OutStream_Tell(self->outstream);
+    MatchPostingWriterIVARS *const ivars = MatchPostWriter_IVARS(self);
+    TermInfoIVARS *const tinfo_ivars = TInfo_IVARS(tinfo);
+    ivars->last_doc_id   = 0;
+    tinfo_ivars->post_filepos = OutStream_Tell(ivars->outstream);
 }
 
 void
 MatchPostWriter_update_skip_info(MatchPostingWriter *self, TermInfo *tinfo) {
-    tinfo->post_filepos = OutStream_Tell(self->outstream);
+    MatchPostingWriterIVARS *const ivars = MatchPostWriter_IVARS(self);
+    TermInfoIVARS *const tinfo_ivars = TInfo_IVARS(tinfo);
+    tinfo_ivars->post_filepos = OutStream_Tell(ivars->outstream);
 }
 
 /***************************************************************************/
@@ -234,43 +249,49 @@ MatchTermInfoStepper*
 MatchTInfoStepper_init(MatchTermInfoStepper *self, Schema *schema) {
     Architecture *arch = Schema_Get_Architecture(schema);
     TermStepper_init((TermStepper*)self);
-    self->skip_interval = Arch_Skip_Interval(arch);
-    self->value = (Obj*)TInfo_new(0);
+    MatchTermInfoStepperIVARS *const ivars = MatchTInfoStepper_IVARS(self);
+    ivars->skip_interval = Arch_Skip_Interval(arch);
+    ivars->value = (Obj*)TInfo_new(0);
     return self;
 }
 
 void
 MatchTInfoStepper_reset(MatchTermInfoStepper *self) {
-    TInfo_Reset((TermInfo*)self->value);
+    MatchTermInfoStepperIVARS *const ivars = MatchTInfoStepper_IVARS(self);
+    TInfo_Reset((TermInfo*)ivars->value);
 }
 
 void
 MatchTInfoStepper_write_key_frame(MatchTermInfoStepper *self,
                                   OutStream *outstream, Obj *value) {
+    MatchTermInfoStepperIVARS *const ivars = MatchTInfoStepper_IVARS(self);
     TermInfo *tinfo    = (TermInfo*)CERTIFY(value, TERMINFO);
     int32_t   doc_freq = TInfo_Get_Doc_Freq(tinfo);
+    TermInfoIVARS *const tinfo_ivars = TInfo_IVARS((TermInfo*)value);
 
     // Write doc_freq.
     OutStream_Write_C32(outstream, doc_freq);
 
     // Write postings file pointer.
-    OutStream_Write_C64(outstream, tinfo->post_filepos);
+    OutStream_Write_C64(outstream, tinfo_ivars->post_filepos);
 
     // Write skip file pointer (maybe).
-    if (doc_freq >= self->skip_interval) {
-        OutStream_Write_C64(outstream, tinfo->skip_filepos);
+    if (doc_freq >= ivars->skip_interval) {
+        OutStream_Write_C64(outstream, tinfo_ivars->skip_filepos);
     }
 
-    TInfo_Mimic((TermInfo*)self->value, (Obj*)tinfo);
+    TInfo_Mimic((TermInfo*)ivars->value, (Obj*)tinfo);
 }
 
 void
 MatchTInfoStepper_write_delta(MatchTermInfoStepper *self,
                               OutStream *outstream, Obj *value) {
+    MatchTermInfoStepperIVARS *const ivars = MatchTInfoStepper_IVARS(self);
     TermInfo *tinfo      = (TermInfo*)CERTIFY(value, TERMINFO);
-    TermInfo *last_tinfo = (TermInfo*)self->value;
+    TermInfo *last_tinfo = (TermInfo*)ivars->value;
     int32_t   doc_freq   = TInfo_Get_Doc_Freq(tinfo);
-    int64_t   post_delta = tinfo->post_filepos - last_tinfo->post_filepos;
+    int64_t   post_delta = TInfo_IVARS(tinfo)->post_filepos
+                           - TInfo_IVARS(last_tinfo)->post_filepos;
 
     // Write doc_freq.
     OutStream_Write_C32(outstream, doc_freq);
@@ -279,49 +300,51 @@ MatchTInfoStepper_write_delta(MatchTermInfoStepper *self,
     OutStream_Write_C64(outstream, post_delta);
 
     // Write skip file pointer (maybe).
-    if (doc_freq >= self->skip_interval) {
-        OutStream_Write_C64(outstream, tinfo->skip_filepos);
+    if (doc_freq >= ivars->skip_interval) {
+        OutStream_Write_C64(outstream, TInfo_IVARS(tinfo)->skip_filepos);
     }
 
-    TInfo_Mimic((TermInfo*)self->value, (Obj*)tinfo);
+    TInfo_Mimic((TermInfo*)ivars->value, (Obj*)tinfo);
 }
 
 void
 MatchTInfoStepper_read_key_frame(MatchTermInfoStepper *self,
                                  InStream *instream) {
-    TermInfo *const tinfo = (TermInfo*)self->value;
+    MatchTermInfoStepperIVARS *const ivars = MatchTInfoStepper_IVARS(self);
+    TermInfoIVARS *const tinfo_ivars = TInfo_IVARS((TermInfo*)ivars->value);
 
     // Read doc freq.
-    tinfo->doc_freq = InStream_Read_C32(instream);
+    tinfo_ivars->doc_freq = InStream_Read_C32(instream);
 
     // Read postings file pointer.
-    tinfo->post_filepos = InStream_Read_C64(instream);
+    tinfo_ivars->post_filepos = InStream_Read_C64(instream);
 
     // Maybe read skip pointer.
-    if (tinfo->doc_freq >= self->skip_interval) {
-        tinfo->skip_filepos = InStream_Read_C64(instream);
+    if (tinfo_ivars->doc_freq >= ivars->skip_interval) {
+        tinfo_ivars->skip_filepos = InStream_Read_C64(instream);
     }
     else {
-        tinfo->skip_filepos = 0;
+        tinfo_ivars->skip_filepos = 0;
     }
 }
 
 void
 MatchTInfoStepper_read_delta(MatchTermInfoStepper *self, InStream *instream) {
-    TermInfo *const tinfo = (TermInfo*)self->value;
+    MatchTermInfoStepperIVARS *const ivars = MatchTInfoStepper_IVARS(self);
+    TermInfoIVARS *const tinfo_ivars = TInfo_IVARS((TermInfo*)ivars->value);
 
     // Read doc freq.
-    tinfo->doc_freq = InStream_Read_C32(instream);
+    tinfo_ivars->doc_freq = InStream_Read_C32(instream);
 
     // Adjust postings file pointer.
-    tinfo->post_filepos += InStream_Read_C64(instream);
+    tinfo_ivars->post_filepos += InStream_Read_C64(instream);
 
     // Maybe read skip pointer.
-    if (tinfo->doc_freq >= self->skip_interval) {
-        tinfo->skip_filepos = InStream_Read_C64(instream);
+    if (tinfo_ivars->doc_freq >= ivars->skip_interval) {
+        tinfo_ivars->skip_filepos = InStream_Read_C64(instream);
     }
     else {
-        tinfo->skip_filepos = 0;
+        tinfo_ivars->skip_filepos = 0;
     }
 }
 

http://git-wip-us.apache.org/repos/asf/lucy/blob/14e863fb/core/Lucy/Index/Posting/RawPosting.c
----------------------------------------------------------------------
diff --git a/core/Lucy/Index/Posting/RawPosting.c b/core/Lucy/Index/Posting/RawPosting.c
index eb87fb2..1fb73be 100644
--- a/core/Lucy/Index/Posting/RawPosting.c
+++ b/core/Lucy/Index/Posting/RawPosting.c
@@ -35,11 +35,12 @@ RawPost_new(void *pre_allocated_memory, int32_t doc_id, uint32_t freq,
             char *term_text, size_t term_text_len) {
     RawPosting *self
         = (RawPosting*)VTable_Init_Obj(RAWPOSTING, pre_allocated_memory);
-    self->doc_id      = doc_id;
-    self->freq        = freq;
-    self->content_len = term_text_len;
-    self->aux_len     = 0;
-    memcpy(&self->blob, term_text, term_text_len);
+    RawPostingIVARS *const ivars = RawPost_IVARS(self);
+    ivars->doc_id      = doc_id;
+    ivars->freq        = freq;
+    ivars->content_len = term_text_len;
+    ivars->aux_len     = 0;
+    memcpy(&ivars->blob, term_text, term_text_len);
 
     return self;
 }
@@ -85,45 +86,54 @@ RawPostWriter_init(RawPostingWriter *self, Schema *schema,
     const int32_t invalid_field_num = 0;
     PostWriter_init((PostingWriter*)self, schema, snapshot, segment,
                     polyreader, invalid_field_num);
-    self->outstream = (OutStream*)INCREF(outstream);
-    self->last_doc_id = 0;
+    RawPostingWriterIVARS *const ivars = RawPostWriter_IVARS(self);
+    ivars->outstream = (OutStream*)INCREF(outstream);
+    ivars->last_doc_id = 0;
     return self;
 }
 
 void
 RawPostWriter_start_term(RawPostingWriter *self, TermInfo *tinfo) {
-    self->last_doc_id   = 0;
-    tinfo->post_filepos = OutStream_Tell(self->outstream);
+    RawPostingWriterIVARS *const ivars = RawPostWriter_IVARS(self);
+    ivars->last_doc_id   = 0;
+    TermInfoIVARS *const tinfo_ivars = TInfo_IVARS(tinfo);
+    tinfo_ivars->post_filepos = OutStream_Tell(ivars->outstream);
 }
 
 void
 RawPostWriter_update_skip_info(RawPostingWriter *self, TermInfo *tinfo) {
-    tinfo->post_filepos = OutStream_Tell(self->outstream);
+    RawPostingWriterIVARS *const ivars = RawPostWriter_IVARS(self);
+    TermInfoIVARS *const tinfo_ivars = TInfo_IVARS(tinfo);
+    tinfo_ivars->post_filepos = OutStream_Tell(ivars->outstream);
 }
 
 void
 RawPostWriter_destroy(RawPostingWriter *self) {
-    DECREF(self->outstream);
+    RawPostingWriterIVARS *const ivars = RawPostWriter_IVARS(self);
+    DECREF(ivars->outstream);
     SUPER_DESTROY(self, RAWPOSTINGWRITER);
 }
 
 void
 RawPostWriter_write_posting(RawPostingWriter *self, RawPosting *posting) {
-    OutStream *const outstream   = self->outstream;
-    const int32_t    doc_id      = posting->doc_id;
-    const uint32_t   delta_doc   = doc_id - self->last_doc_id;
-    char  *const     aux_content = posting->blob + posting->content_len;
-    if (posting->freq == 1) {
+    RawPostingWriterIVARS *const ivars = RawPostWriter_IVARS(self);
+    RawPostingIVARS *const posting_ivars = RawPost_IVARS(posting);
+    OutStream *const outstream   = ivars->outstream;
+    const int32_t    doc_id      = posting_ivars->doc_id;
+    const uint32_t   delta_doc   = doc_id - ivars->last_doc_id;
+    char  *const     aux_content = posting_ivars->blob
+                                   + posting_ivars->content_len;
+    if (posting_ivars->freq == 1) {
         const uint32_t doc_code = (delta_doc << 1) | 1;
         OutStream_Write_C32(outstream, doc_code);
     }
     else {
         const uint32_t doc_code = delta_doc << 1;
         OutStream_Write_C32(outstream, doc_code);
-        OutStream_Write_C32(outstream, posting->freq);
+        OutStream_Write_C32(outstream, posting_ivars->freq);
     }
-    OutStream_Write_Bytes(outstream, aux_content, posting->aux_len);
-    self->last_doc_id = doc_id;
+    OutStream_Write_Bytes(outstream, aux_content, posting_ivars->aux_len);
+    ivars->last_doc_id = doc_id;
 }
 
 

http://git-wip-us.apache.org/repos/asf/lucy/blob/14e863fb/core/Lucy/Index/Posting/RichPosting.c
----------------------------------------------------------------------
diff --git a/core/Lucy/Index/Posting/RichPosting.c b/core/Lucy/Index/Posting/RichPosting.c
index 30b4f39..9715765 100644
--- a/core/Lucy/Index/Posting/RichPosting.c
+++ b/core/Lucy/Index/Posting/RichPosting.c
@@ -33,8 +33,8 @@
 #include "Lucy/Util/MemoryPool.h"
 
 #define FREQ_MAX_LEN     C32_MAX_BYTES
-#define MAX_RAW_POSTING_LEN(_text_len, _freq) \
-    (              sizeof(RawPosting) \
+#define MAX_RAW_POSTING_LEN(_raw_posting_size, _text_len, _freq) \
+    (              _raw_posting_size \
                    + _text_len                /* term text content */ \
                    + FREQ_MAX_LEN             /* freq c32 */ \
                    + (C32_MAX_BYTES * _freq)  /* positions deltas */ \
@@ -50,46 +50,49 @@ RichPost_new(Similarity *sim) {
 RichPosting*
 RichPost_init(RichPosting *self, Similarity *sim) {
     ScorePost_init((ScorePosting*)self, sim);
-    self->prox_boosts     = NULL;
+    RichPostingIVARS *const ivars = RichPost_IVARS(self);
+    ivars->prox_boosts     = NULL;
     return self;
 }
 
 void
 RichPost_destroy(RichPosting *self) {
-    FREEMEM(self->prox_boosts);
+    RichPostingIVARS *const ivars = RichPost_IVARS(self);
+    FREEMEM(ivars->prox_boosts);
     SUPER_DESTROY(self, RICHPOSTING);
 }
 
 void
 RichPost_read_record(RichPosting *self, InStream *instream) {
-    float *const norm_decoder = self->norm_decoder;
+    RichPostingIVARS *const ivars = RichPost_IVARS(self);
+    float *const norm_decoder = ivars->norm_decoder;
     uint32_t  num_prox = 0;
     uint32_t  position = 0;
     float     aggregate_weight = 0.0;
 
     // Decode delta doc.
     uint32_t doc_code = InStream_Read_C32(instream);
-    self->doc_id += doc_code >> 1;
+    ivars->doc_id += doc_code >> 1;
 
     // If the stored num was odd, the freq is 1.
     if (doc_code & 1) {
-        self->freq = 1;
+        ivars->freq = 1;
     }
     // Otherwise, freq was stored as a C32.
     else {
-        self->freq = InStream_Read_C32(instream);
+        ivars->freq = InStream_Read_C32(instream);
     }
 
     // Read positions, aggregate per-position boost byte into weight.
-    num_prox = self->freq;
-    if (num_prox > self->prox_cap) {
-        self->prox
-            = (uint32_t*)REALLOCATE(self->prox, num_prox * sizeof(uint32_t));
-        self->prox_boosts
-            = (float*)REALLOCATE(self->prox_boosts, num_prox * sizeof(float));
+    num_prox = ivars->freq;
+    if (num_prox > ivars->prox_cap) {
+        ivars->prox
+            = (uint32_t*)REALLOCATE(ivars->prox, num_prox * sizeof(uint32_t));
+        ivars->prox_boosts
+            = (float*)REALLOCATE(ivars->prox_boosts, num_prox * sizeof(float));
     }
-    uint32_t *positions    = self->prox;
-    float    *prox_boosts  = self->prox_boosts;
+    uint32_t *positions    = ivars->prox;
+    float    *prox_boosts  = ivars->prox_boosts;
 
     while (num_prox--) {
         position += InStream_Read_C32(instream);
@@ -98,7 +101,7 @@ RichPost_read_record(RichPosting *self, InStream *instream) {
         aggregate_weight += *prox_boosts;
         prox_boosts++;
     }
-    self->weight = aggregate_weight / self->freq;
+    ivars->weight = aggregate_weight / ivars->freq;
 }
 
 void
@@ -106,38 +109,42 @@ RichPost_add_inversion_to_pool(RichPosting *self, PostingPool *post_pool,
                                Inversion *inversion, FieldType *type,
                                int32_t doc_id, float doc_boost,
                                float length_norm) {
+    RichPostingIVARS *const ivars = RichPost_IVARS(self);
     MemoryPool *mem_pool = PostPool_Get_Mem_Pool(post_pool);
-    Similarity *sim = self->sim;
+    Similarity *sim = ivars->sim;
     float       field_boost = doc_boost * FType_Get_Boost(type) * length_norm;
+    const size_t base_size = VTable_Get_Obj_Alloc_Size(RAWPOSTING);
     Token     **tokens;
     uint32_t    freq;
 
     Inversion_Reset(inversion);
     while ((tokens = Inversion_Next_Cluster(inversion, &freq)) != NULL) {
-        Token   *token          = *tokens;
-        uint32_t raw_post_bytes = MAX_RAW_POSTING_LEN(token->len, freq);
+        TokenIVARS *const token_ivars = Token_IVARS(*tokens);
+        uint32_t raw_post_bytes
+            = MAX_RAW_POSTING_LEN(base_size, token_ivars->len, freq);
         RawPosting *raw_posting
             = RawPost_new(MemPool_Grab(mem_pool, raw_post_bytes), doc_id,
-                          freq, token->text, token->len);
-        char *const start = raw_posting->blob + token->len;
+                          freq, token_ivars->text, token_ivars->len);
+        RawPostingIVARS *const raw_post_ivars = RawPost_IVARS(raw_posting);
+        char *const start = raw_post_ivars->blob + token_ivars->len;
         char *dest = start;
         uint32_t last_prox = 0;
 
         // Positions and boosts.
         for (uint32_t i = 0; i < freq; i++) {
-            Token *const t = tokens[i];
-            const uint32_t prox_delta = t->pos - last_prox;
-            const float boost = field_boost * t->boost;
+            TokenIVARS *const t_ivars = Token_IVARS(tokens[i]);
+            const uint32_t prox_delta = t_ivars->pos - last_prox;
+            const float boost = field_boost * t_ivars->boost;
 
             NumUtil_encode_c32(prox_delta, &dest);
-            last_prox = t->pos;
+            last_prox = t_ivars->pos;
 
             *((uint8_t*)dest) = Sim_Encode_Norm(sim, boost);
             dest++;
         }
 
         // Resize raw posting memory allocation.
-        raw_posting->aux_len = dest - start;
+        raw_post_ivars->aux_len = dest - start;
         raw_post_bytes = dest - (char*)raw_posting;
         MemPool_Resize(mem_pool, raw_posting, raw_post_bytes);
         PostPool_Feed(post_pool, &raw_posting);
@@ -155,12 +162,14 @@ RichPost_read_raw(RichPosting *self, InStream *instream, int32_t last_doc_id,
     const uint32_t freq           = (doc_code & 1)
                                     ? 1
                                     : InStream_Read_C32(instream);
-    size_t raw_post_bytes         = MAX_RAW_POSTING_LEN(text_size, freq);
+    const size_t base_size        = VTable_Get_Obj_Alloc_Size(RAWPOSTING);
+    size_t raw_post_bytes         = MAX_RAW_POSTING_LEN(base_size, text_size, freq);
     void *const allocation        = MemPool_Grab(mem_pool, raw_post_bytes);
     RawPosting *const raw_posting
         = RawPost_new(allocation, doc_id, freq, text_buf, text_size);
+        RawPostingIVARS *const raw_post_ivars = RawPost_IVARS(raw_posting);
     uint32_t num_prox = freq;
-    char *const start = raw_posting->blob + text_size;
+    char *const start = raw_post_ivars->blob + text_size;
     char *      dest  = start;
     UNUSED_VAR(self);
 
@@ -172,7 +181,7 @@ RichPost_read_raw(RichPosting *self, InStream *instream, int32_t last_doc_id,
     }
 
     // Resize raw posting memory allocation.
-    raw_posting->aux_len = dest - start;
+    raw_post_ivars->aux_len = dest - start;
     raw_post_bytes       = dest - (char*)raw_posting;
     MemPool_Resize(mem_pool, raw_posting, raw_post_bytes);
 

http://git-wip-us.apache.org/repos/asf/lucy/blob/14e863fb/core/Lucy/Index/Posting/ScorePosting.c
----------------------------------------------------------------------
diff --git a/core/Lucy/Index/Posting/ScorePosting.c b/core/Lucy/Index/Posting/ScorePosting.c
index 08dee59..f02de37 100644
--- a/core/Lucy/Index/Posting/ScorePosting.c
+++ b/core/Lucy/Index/Posting/ScorePosting.c
@@ -35,8 +35,8 @@
 
 #define FIELD_BOOST_LEN  1
 #define FREQ_MAX_LEN     C32_MAX_BYTES
-#define MAX_RAW_POSTING_LEN(_text_len, _freq) \
-    (              sizeof(RawPosting) \
+#define MAX_RAW_POSTING_LEN(_raw_post_size, _text_len, _freq) \
+    (              _raw_post_size \
                    + _text_len                /* term text content */ \
                    + FIELD_BOOST_LEN          /* field boost byte */ \
                    + FREQ_MAX_LEN             /* freq c32 */ \
@@ -52,23 +52,25 @@ ScorePost_new(Similarity *sim) {
 ScorePosting*
 ScorePost_init(ScorePosting *self, Similarity *sim) {
     MatchPost_init((MatchPosting*)self, sim);
-    self->norm_decoder = Sim_Get_Norm_Decoder(sim);
-    self->freq         = 0;
-    self->weight       = 0.0;
-    self->prox         = NULL;
-    self->prox_cap     = 0;
+    ScorePostingIVARS *const ivars = ScorePost_IVARS(self);
+    ivars->norm_decoder = Sim_Get_Norm_Decoder(sim);
+    ivars->freq         = 0;
+    ivars->weight       = 0.0;
+    ivars->prox         = NULL;
+    ivars->prox_cap     = 0;
     return self;
 }
 
 void
 ScorePost_destroy(ScorePosting *self) {
-    FREEMEM(self->prox);
+    ScorePostingIVARS *const ivars = ScorePost_IVARS(self);
+    FREEMEM(ivars->prox);
     SUPER_DESTROY(self, SCOREPOSTING);
 }
 
 uint32_t*
 ScorePost_get_prox(ScorePosting *self) {
-    return self->prox;
+    return ScorePost_IVARS(self)->prox;
 }
 
 void
@@ -76,21 +78,25 @@ ScorePost_add_inversion_to_pool(ScorePosting *self, PostingPool *post_pool,
                                 Inversion *inversion, FieldType *type,
                                 int32_t doc_id, float doc_boost,
                                 float length_norm) {
+    ScorePostingIVARS *const ivars = ScorePost_IVARS(self);
     MemoryPool     *mem_pool = PostPool_Get_Mem_Pool(post_pool);
-    Similarity     *sim = self->sim;
+    Similarity     *sim = ivars->sim;
     float           field_boost = doc_boost * FType_Get_Boost(type) * length_norm;
     const uint8_t   field_boost_byte  = Sim_Encode_Norm(sim, field_boost);
+    const size_t    base_size = VTable_Get_Obj_Alloc_Size(RAWPOSTING);
     Token         **tokens;
     uint32_t        freq;
 
     Inversion_Reset(inversion);
     while ((tokens = Inversion_Next_Cluster(inversion, &freq)) != NULL) {
-        Token   *token          = *tokens;
-        uint32_t raw_post_bytes = MAX_RAW_POSTING_LEN(token->len, freq);
+        TokenIVARS *const token_ivars = Token_IVARS(*tokens);
+        uint32_t raw_post_bytes
+            = MAX_RAW_POSTING_LEN(base_size, token_ivars->len, freq);
         RawPosting *raw_posting
             = RawPost_new(MemPool_Grab(mem_pool, raw_post_bytes), doc_id,
-                          freq, token->text, token->len);
-        char *const start  = raw_posting->blob + token->len;
+                          freq, token_ivars->text, token_ivars->len);
+        RawPostingIVARS *const raw_post_ivars = RawPost_IVARS(raw_posting);
+        char *const start  = raw_post_ivars->blob + token_ivars->len;
         char *dest         = start;
         uint32_t last_prox = 0;
 
@@ -100,14 +106,14 @@ ScorePost_add_inversion_to_pool(ScorePosting *self, PostingPool *post_pool,
 
         // Positions.
         for (uint32_t i = 0; i < freq; i++) {
-            Token *const t = tokens[i];
-            const uint32_t prox_delta = t->pos - last_prox;
+            TokenIVARS *const t_ivars = Token_IVARS(tokens[i]);
+            const uint32_t prox_delta = t_ivars->pos - last_prox;
             NumUtil_encode_c32(prox_delta, &dest);
-            last_prox = t->pos;
+            last_prox = t_ivars->pos;
         }
 
         // Resize raw posting memory allocation.
-        raw_posting->aux_len = dest - start;
+        raw_post_ivars->aux_len = dest - start;
         raw_post_bytes = dest - (char*)raw_posting;
         MemPool_Resize(mem_pool, raw_posting, raw_post_bytes);
         PostPool_Feed(post_pool, &raw_posting);
@@ -116,13 +122,15 @@ ScorePost_add_inversion_to_pool(ScorePosting *self, PostingPool *post_pool,
 
 void
 ScorePost_reset(ScorePosting *self) {
-    self->doc_id = 0;
-    self->freq   = 0;
-    self->weight = 0.0;
+    ScorePostingIVARS *const ivars = ScorePost_IVARS(self);
+    ivars->doc_id = 0;
+    ivars->freq   = 0;
+    ivars->weight = 0.0;
 }
 
 void
 ScorePost_read_record(ScorePosting *self, InStream *instream) {
+    ScorePostingIVARS *const ivars = ScorePost_IVARS(self);
     uint32_t  position = 0;
     const size_t max_start_bytes = (C32_MAX_BYTES * 2) + 1;
     char *buf = InStream_Buf(instream, max_start_bytes);
@@ -130,26 +138,26 @@ ScorePost_read_record(ScorePosting *self, InStream *instream) {
     const uint32_t doc_delta = doc_code >> 1;
 
     // Apply delta doc and retrieve freq.
-    self->doc_id   += doc_delta;
+    ivars->doc_id   += doc_delta;
     if (doc_code & 1) {
-        self->freq = 1;
+        ivars->freq = 1;
     }
     else {
-        self->freq = NumUtil_decode_c32(&buf);
+        ivars->freq = NumUtil_decode_c32(&buf);
     }
 
     // Decode boost/norm byte.
-    self->weight = self->norm_decoder[*(uint8_t*)buf];
+    ivars->weight = ivars->norm_decoder[*(uint8_t*)buf];
     buf++;
 
     // Read positions.
-    uint32_t num_prox = self->freq;
-    if (num_prox > self->prox_cap) {
-        self->prox = (uint32_t*)REALLOCATE(
-                         self->prox, num_prox * sizeof(uint32_t));
-        self->prox_cap = num_prox;
+    uint32_t num_prox = ivars->freq;
+    if (num_prox > ivars->prox_cap) {
+        ivars->prox = (uint32_t*)REALLOCATE(
+                         ivars->prox, num_prox * sizeof(uint32_t));
+        ivars->prox_cap = num_prox;
     }
-    uint32_t *positions = self->prox;
+    uint32_t *positions = ivars->prox;
 
     InStream_Advance_Buf(instream, buf);
     buf = InStream_Buf(instream, num_prox * C32_MAX_BYTES);
@@ -173,12 +181,14 @@ ScorePost_read_raw(ScorePosting *self, InStream *instream,
     const uint32_t freq           = (doc_code & 1)
                                     ? 1
                                     : InStream_Read_C32(instream);
-    size_t raw_post_bytes         = MAX_RAW_POSTING_LEN(text_size, freq);
+    const size_t base_size        = VTable_Get_Obj_Alloc_Size(RAWPOSTING);
+    size_t raw_post_bytes         = MAX_RAW_POSTING_LEN(base_size, text_size, freq);
     void *const allocation        = MemPool_Grab(mem_pool, raw_post_bytes);
     RawPosting *const raw_posting
         = RawPost_new(allocation, doc_id, freq, text_buf, text_size);
+    RawPostingIVARS *const raw_post_ivars = RawPost_IVARS(raw_posting);
     uint32_t num_prox = freq;
-    char *const start = raw_posting->blob + text_size;
+    char *const start = raw_post_ivars->blob + text_size;
     char *dest        = start;
     UNUSED_VAR(self);
 
@@ -192,7 +202,7 @@ ScorePost_read_raw(ScorePosting *self, InStream *instream,
     }
 
     // Resize raw posting memory allocation.
-    raw_posting->aux_len = dest - start;
+    raw_post_ivars->aux_len = dest - start;
     raw_post_bytes       = dest - (char*)raw_posting;
     MemPool_Resize(mem_pool, raw_posting, raw_post_bytes);
 
@@ -215,11 +225,12 @@ ScorePostMatcher_init(ScorePostingMatcher *self, Similarity *sim,
                       PostingList *plist, Compiler *compiler) {
     // Init.
     TermMatcher_init((TermMatcher*)self, sim, plist, compiler);
+    ScorePostingMatcherIVARS *const ivars = ScorePostMatcher_IVARS(self);
 
     // Fill score cache.
-    self->score_cache = (float*)MALLOCATE(TERMMATCHER_SCORE_CACHE_SIZE * sizeof(float));
+    ivars->score_cache = (float*)MALLOCATE(TERMMATCHER_SCORE_CACHE_SIZE * sizeof(float));
     for (uint32_t i = 0; i < TERMMATCHER_SCORE_CACHE_SIZE; i++) {
-        self->score_cache[i] = Sim_TF(sim, (float)i) * self->weight;
+        ivars->score_cache[i] = Sim_TF(sim, (float)i) * ivars->weight;
     }
 
     return self;
@@ -227,23 +238,26 @@ ScorePostMatcher_init(ScorePostingMatcher *self, Similarity *sim,
 
 float
 ScorePostMatcher_score(ScorePostingMatcher* self) {
-    ScorePosting *const posting = (ScorePosting*)self->posting;
-    const uint32_t freq = posting->freq;
+    ScorePostingMatcherIVARS *const ivars = ScorePostMatcher_IVARS(self);
+    ScorePostingIVARS *const posting_ivars
+        = ScorePost_IVARS((ScorePosting*)ivars->posting);
+    const uint32_t freq = posting_ivars->freq;
 
     // Calculate initial score based on frequency of term.
     float score = (freq < TERMMATCHER_SCORE_CACHE_SIZE)
-                  ? self->score_cache[freq] // cache hit
-                  : Sim_TF(self->sim, (float)freq) * self->weight;
+                  ? ivars->score_cache[freq] // cache hit
+                  : Sim_TF(ivars->sim, (float)freq) * ivars->weight;
 
     // Factor in field-length normalization and doc/field/prox boost.
-    score *= posting->weight;
+    score *= posting_ivars->weight;
 
     return score;
 }
 
 void
 ScorePostMatcher_destroy(ScorePostingMatcher *self) {
-    FREEMEM(self->score_cache);
+    ScorePostingMatcherIVARS *const ivars = ScorePostMatcher_IVARS(self);
+    FREEMEM(ivars->score_cache);
     SUPER_DESTROY(self, SCOREPOSTINGMATCHER);
 }