Change return type for Peek() and Fetch(). Modify SortExternal and subclasses so that Peek() and Fetch return Obj* rather than a void* which was actually Obj**.
Project: http://git-wip-us.apache.org/repos/asf/lucy/repo Commit: http://git-wip-us.apache.org/repos/asf/lucy/commit/07a6c3ce Tree: http://git-wip-us.apache.org/repos/asf/lucy/tree/07a6c3ce Diff: http://git-wip-us.apache.org/repos/asf/lucy/diff/07a6c3ce Branch: refs/heads/sortex_ptr_only Commit: 07a6c3ce2b6900b5c27d6381bf3483b31fa5880e Parents: c22026c Author: Marvin Humphrey <[email protected]> Authored: Fri Jan 4 16:16:14 2013 -0800 Committer: Marvin Humphrey <[email protected]> Committed: Fri Jan 4 16:16:14 2013 -0800 ---------------------------------------------------------------------- core/Lucy/Index/PostingPool.c | 11 ++----- core/Lucy/Index/SortFieldWriter.c | 6 +-- core/Lucy/Util/SortExternal.c | 13 ++++--- core/Lucy/Util/SortExternal.cfh | 4 +- perl/buildlib/Lucy/Build/Binding/Misc.pm | 43 ------------------------- 5 files changed, 14 insertions(+), 63 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/lucy/blob/07a6c3ce/core/Lucy/Index/PostingPool.c ---------------------------------------------------------------------- diff --git a/core/Lucy/Index/PostingPool.c b/core/Lucy/Index/PostingPool.c index 8a8cdd8..f8bf304 100644 --- a/core/Lucy/Index/PostingPool.c +++ b/core/Lucy/Index/PostingPool.c @@ -356,9 +356,8 @@ S_write_terms_and_postings(PostingPool *self, PostingWriter *post_writer, = Arch_Skip_Interval(Schema_Get_Architecture(self->schema)); // Prime heldover variables. - RawPosting *posting = (RawPosting*)CERTIFY( - (*(RawPosting**)PostPool_Fetch(self)), - RAWPOSTING); + RawPosting *posting + = (RawPosting*)CERTIFY(PostPool_Fetch(self), RAWPOSTING); CB_Mimic_Str(last_term_text, posting->blob, posting->content_len); char *last_text_buf = (char*)CB_Get_Ptr8(last_term_text); uint32_t last_text_size = CB_Get_Size(last_term_text); @@ -443,11 +442,7 @@ S_write_terms_and_postings(PostingPool *self, PostingWriter *post_writer, // Retrieve the next posting from the sort pool. // DECREF(posting); // No!! DON'T destroy!!! - - void *address = PostPool_Fetch(self); - posting = address - ? *(RawPosting**)address - : NULL; + posting = (RawPosting*)PostPool_Fetch(self); } // Clean up. http://git-wip-us.apache.org/repos/asf/lucy/blob/07a6c3ce/core/Lucy/Index/SortFieldWriter.c ---------------------------------------------------------------------- diff --git a/core/Lucy/Index/SortFieldWriter.c b/core/Lucy/Index/SortFieldWriter.c index 999562b..545b031 100644 --- a/core/Lucy/Index/SortFieldWriter.c +++ b/core/Lucy/Index/SortFieldWriter.c @@ -535,8 +535,7 @@ 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_ptr = (SFWriterElem**)SortFieldWriter_Fetch(self); - SFWriterElem *elem = *elem_ptr; + SFWriterElem *elem = (SFWriterElem*)SortFieldWriter_Fetch(self); ords[elem->doc_id] = ord; ords[0] = 0; @@ -544,8 +543,7 @@ 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_ptr = (SFWriterElem**)SortFieldWriter_Fetch(self))) { - elem = *elem_ptr; + while (NULL != (elem = (SFWriterElem*)SortFieldWriter_Fetch(self))) { if (elem->value != last_val_address) { int32_t comparison = FType_Compare_Values(self->type, elem->value, val); http://git-wip-us.apache.org/repos/asf/lucy/blob/07a6c3ce/core/Lucy/Util/SortExternal.c ---------------------------------------------------------------------- diff --git a/core/Lucy/Util/SortExternal.c b/core/Lucy/Util/SortExternal.c index 8fab003..7ef1cf4 100644 --- a/core/Lucy/Util/SortExternal.c +++ b/core/Lucy/Util/SortExternal.c @@ -87,28 +87,29 @@ SortEx_feed(SortExternal *self, Obj *item) { self->cache_max++; } -static INLINE void* +static INLINE Obj* SI_peek(SortExternal *self) { if (self->cache_tick >= self->cache_max) { S_refill_cache(self); } if (self->cache_max > 0) { - return self->cache + self->cache_tick * sizeof(Obj*); + Obj **elems = (Obj**)self->cache; + return elems[self->cache_tick]; } else { return NULL; } } -void* +Obj* SortEx_fetch(SortExternal *self) { - void *address = SI_peek(self); + Obj *item = SI_peek(self); self->cache_tick++; - return address; + return item; } -void* +Obj* SortEx_peek(SortExternal *self) { return SI_peek(self); } http://git-wip-us.apache.org/repos/asf/lucy/blob/07a6c3ce/core/Lucy/Util/SortExternal.cfh ---------------------------------------------------------------------- diff --git a/core/Lucy/Util/SortExternal.cfh b/core/Lucy/Util/SortExternal.cfh index ee1b230..fa6be96 100644 --- a/core/Lucy/Util/SortExternal.cfh +++ b/core/Lucy/Util/SortExternal.cfh @@ -92,13 +92,13 @@ abstract class Lucy::Util::SortExternal cnick SortEx /** Fetch the next sorted item from the sort pool. Invalid prior to * calling Flip(). Returns NULL when all elements have been exhausted. */ - nullable void* + incremented nullable Obj* Fetch(SortExternal *self); /** Preview the next item that Fetch will return, but don't pop it. * Invalid prior to calling Flip(). */ - nullable void* + nullable Obj* Peek(SortExternal *self); /** Add a run to the sortex's collection. http://git-wip-us.apache.org/repos/asf/lucy/blob/07a6c3ce/perl/buildlib/Lucy/Build/Binding/Misc.pm ---------------------------------------------------------------------- diff --git a/perl/buildlib/Lucy/Build/Binding/Misc.pm b/perl/buildlib/Lucy/Build/Binding/Misc.pm index e59f760..255adf7 100644 --- a/perl/buildlib/Lucy/Build/Binding/Misc.pm +++ b/perl/buildlib/Lucy/Build/Binding/Misc.pm @@ -369,53 +369,10 @@ sub bind_testschema { } sub bind_bbsortex { - my @hand_rolled = qw( - Fetch - Peek - ); - my $xs_code = <<'END_XS_CODE'; -MODULE = Lucy PACKAGE = Lucy::Test::Util::BBSortEx - -SV* -fetch(self) - lucy_BBSortEx *self; -CODE: -{ - void *address = Lucy_BBSortEx_Fetch(self); - if (address) { - RETVAL = XSBind_cfish_to_perl(*(lucy_Obj**)address); - CFISH_DECREF(*(lucy_Obj**)address); - } - else { - RETVAL = newSV(0); - } -} -OUTPUT: RETVAL - -SV* -peek(self) - lucy_BBSortEx *self; -CODE: -{ - void *address = Lucy_BBSortEx_Peek(self); - if (address) { - RETVAL = XSBind_cfish_to_perl(*(lucy_Obj**)address); - } - else { - RETVAL = newSV(0); - } -} -OUTPUT: RETVAL - -END_XS_CODE - my $binding = Clownfish::CFC::Binding::Perl::Class->new( parcel => "Lucy", class_name => "Lucy::Test::Util::BBSortEx", ); - $binding->exclude_method($_) for @hand_rolled; - $binding->append_xs($xs_code); - Clownfish::CFC::Binding::Perl::Class->register($binding); }
