lucy-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mar...@apache.org
Subject [lucy-commits] [2/3] git commit: refs/heads/sortex_ptr_only - Change SortFieldWriter to use pointer-sized elems.
Date Fri, 04 Jan 2013 21:20:34 GMT
Change SortFieldWriter to use pointer-sized elems.

SortFieldWriter is the only subclass of SortExternal where the elements
have been anything other than pointers.  By changing it to use pointers,
we enable subsequent commits simplifying SortExternal by limiting it to
sorting pointers only.


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

Branch: refs/heads/sortex_ptr_only
Commit: d4b7bac9eaca46836eeeb47d8c5381469d2b7ae0
Parents: d586080
Author: Marvin Humphrey <marvin@rectangular.com>
Authored: Thu Jan 3 17:57:22 2013 -0800
Committer: Marvin Humphrey <marvin@rectangular.com>
Committed: Fri Jan 4 13:12:59 2013 -0800

----------------------------------------------------------------------
 core/Lucy/Index/SortFieldWriter.c |   24 ++++++++++++++++--------
 1 files changed, 16 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucy/blob/d4b7bac9/core/Lucy/Index/SortFieldWriter.c
----------------------------------------------------------------------
diff --git a/core/Lucy/Index/SortFieldWriter.c b/core/Lucy/Index/SortFieldWriter.c
index 57eb999..26fd197 100644
--- a/core/Lucy/Index/SortFieldWriter.c
+++ b/core/Lucy/Index/SortFieldWriter.c
@@ -76,7 +76,7 @@ SortFieldWriter_init(SortFieldWriter *self, Schema *schema,
                      OutStream *temp_ord_out, OutStream *temp_ix_out,
                      OutStream *temp_dat_out) {
     // Init.
-    SortEx_init((SortExternal*)self, sizeof(SFWriterElem));
+    SortEx_init((SortExternal*)self, sizeof(SFWriterElem*));
     self->null_ord        = -1;
     self->count           = 0;
     self->ord_start       = 0;
@@ -131,6 +131,11 @@ SortFieldWriter_clear_cache(SortFieldWriter *self) {
     SortFieldWriter_Clear_Cache_t super_clear_cache
         = SUPER_METHOD_PTR(self->vtable, Lucy_SortFieldWriter_Clear_Cache);
     super_clear_cache(self);
+    // Note that we have not called MemPool_Release_All() on our memory pool.
+    // This is because the pool is shared amongst multiple SortFieldWriters
+    // which belong to a parent SortWriter; it is the responsibility of the
+    // parent SortWriter to release the memory pool once **all** of its child
+    // SortFieldWriters have cleared their caches.
 }
 
 void
@@ -180,9 +185,10 @@ S_find_unique_value(Hash *uniq_vals, Obj *val) {
 void
 SortFieldWriter_add(SortFieldWriter *self, int32_t doc_id, Obj *value) {
     // Uniq-ify the value, and record it for this document.
-    SFWriterElem elem;
-    elem.value = S_find_unique_value(self->uniq_vals, value);
-    elem.doc_id = doc_id;
+    SFWriterElem *elem
+        = (SFWriterElem*)MemPool_Grab(self->mem_pool, sizeof(SFWriterElem));
+    elem->value = S_find_unique_value(self->uniq_vals, value);
+    elem->doc_id = doc_id;
     SortFieldWriter_Feed(self, &elem);
     self->count++;
 }
@@ -322,8 +328,8 @@ S_write_val(Obj *val, int8_t prim_id, OutStream *ix_out, OutStream *dat_out,
 
 int
 SortFieldWriter_compare(SortFieldWriter *self, void *va, void *vb) {
-    SFWriterElem *a = (SFWriterElem*)va;
-    SFWriterElem *b = (SFWriterElem*)vb;
+    SFWriterElem *a = *(SFWriterElem**)va;
+    SFWriterElem *b = *(SFWriterElem**)vb;
     int32_t comparison
         = FType_null_back_compare_values(self->type, a->value, b->value);
     if (comparison == 0) { comparison = b->doc_id - a->doc_id; }
@@ -530,7 +536,8 @@ S_write_files(SortFieldWriter *self, OutStream *ord_out, OutStream *ix_out,
 
     // Grab the first item and record its ord.  Add a dummy ord for invalid
     // doc id 0.
-    SFWriterElem *elem = (SFWriterElem*)SortFieldWriter_Fetch(self);
+    SFWriterElem **elem_ptr = (SFWriterElem**)SortFieldWriter_Fetch(self);
+    SFWriterElem *elem = *elem_ptr;
     ords[elem->doc_id] = ord;
     ords[0] = 0;
 
@@ -538,7 +545,8 @@ S_write_files(SortFieldWriter *self, OutStream *ord_out, OutStream *ix_out,
     Obj *val = Obj_Clone(elem->value);
     Obj *last_val_address = elem->value;
     S_write_val(elem->value, prim_id, ix_out, dat_out, dat_start);
-    while (NULL != (elem = (SFWriterElem*)SortFieldWriter_Fetch(self))) {
+    while (NULL != (elem_ptr = (SFWriterElem**)SortFieldWriter_Fetch(self))) {
+        elem = *elem_ptr;
         if (elem->value != last_val_address) {
             int32_t comparison
                 = FType_Compare_Values(self->type, elem->value, val);


Mime
View raw message