Author: rooneg
Date: Thu Mar 3 17:34:39 2005
New Revision: 156116
URL: http://svn.apache.org/viewcvs?view=rev&rev=156116
Log:
Start cleaning up our use of lcn_error_t.
There's no reason to be exiting from an iteration by creating an error,
it involves creating a new pool, which means mutex locking, allocating
an 8K buffer, and who knows what else. Instead, we're now using a
separate boolean parameter to signal when it's time to break out of the
loop.
This updates the lcn_doc_iter_next interface to use the new style.
* include/lcn_index.h
(lcn_doc_iter_next): add a boolean parameter, update docs.
* src/index/index.c
(lcn_doc_iter_next): add new parameter, set it to TRUE by default,
to FALSE when we run out of steam.
* src/search/scorer.c
(term_scorer_next_internal): update call to lcn_doc_iter_next.
* src/cmdline/main.c
(lcn_termdocs_cmd): ditto.
* test/index/index_test.c
(test_index_term_docs): ditto.
Modified:
incubator/lucene4c/trunk/include/lcn_index.h
incubator/lucene4c/trunk/src/cmdline/main.c
incubator/lucene4c/trunk/src/index/index.c
incubator/lucene4c/trunk/src/search/scorer.c
incubator/lucene4c/trunk/test/index/index_test.c
Modified: incubator/lucene4c/trunk/include/lcn_index.h
URL:
http://svn.apache.org/viewcvs/incubator/lucene4c/trunk/include/lcn_index.h?view=diff&r1=156115&r2=156116
==============================================================================
--- incubator/lucene4c/trunk/include/lcn_index.h (original)
+++ incubator/lucene4c/trunk/include/lcn_index.h Thu Mar 3 17:34:39 2005
@@ -58,9 +58,10 @@
/** Move @a itr to the next document.
*
- * Returns an @c APR_EOF error when the last document has been returned.
+ * If the increment was successful, @a next is TRUE, if it moved us past
+ * the end of the sequence @a next is FALSE.
*/
-lcn_error_t * lcn_doc_iter_next (lcn_doc_iter_t *itr);
+lcn_error_t * lcn_doc_iter_next (lcn_boolean_t *next, lcn_doc_iter_t *itr);
/* XXX need an interface to read multiple doc/freq pairs at once. */
Modified: incubator/lucene4c/trunk/src/cmdline/main.c
URL:
http://svn.apache.org/viewcvs/incubator/lucene4c/trunk/src/cmdline/main.c?view=diff&r1=156115&r2=156116
==============================================================================
--- incubator/lucene4c/trunk/src/cmdline/main.c (original)
+++ incubator/lucene4c/trunk/src/cmdline/main.c Thu Mar 3 17:34:39 2005
@@ -124,6 +124,7 @@
{
lcn_doc_iter_t *itr;
apr_pool_t *subpool;
+ lcn_boolean_t next;
lcn_char_t *pfield;
lcn_error_t *err;
lcn_index_t *idx;
@@ -143,7 +144,7 @@
LCN_ERR (print_doc_field (idx, lcn_doc_iter_doc (itr), pfield, subpool));
- while ((err = lcn_doc_iter_next (itr)) == LCN_NO_ERROR)
+ while ((err = lcn_doc_iter_next (&next, itr)) == LCN_NO_ERROR && next)
{
apr_pool_clear (subpool);
Modified: incubator/lucene4c/trunk/src/index/index.c
URL:
http://svn.apache.org/viewcvs/incubator/lucene4c/trunk/src/index/index.c?view=diff&r1=156115&r2=156116
==============================================================================
--- incubator/lucene4c/trunk/src/index/index.c (original)
+++ incubator/lucene4c/trunk/src/index/index.c Thu Mar 3 17:34:39 2005
@@ -84,8 +84,10 @@
}
lcn_error_t *
-lcn_doc_iter_next (lcn_doc_iter_t *itr)
+lcn_doc_iter_next (lcn_boolean_t *next, lcn_doc_iter_t *itr)
{
+ *next = TRUE;
+
if (++itr->idx_in_seg == itr->count_in_seg)
{
while (++itr->cur_seg < itr->num_segs)
@@ -111,7 +113,7 @@
return LCN_NO_ERROR;
}
- return lcn_error_create (APR_EOF, NULL, "iteration finished");
+ *next = FALSE;
}
return LCN_NO_ERROR;
Modified: incubator/lucene4c/trunk/src/search/scorer.c
URL:
http://svn.apache.org/viewcvs/incubator/lucene4c/trunk/src/search/scorer.c?view=diff&r1=156115&r2=156116
==============================================================================
--- incubator/lucene4c/trunk/src/search/scorer.c (original)
+++ incubator/lucene4c/trunk/src/search/scorer.c Thu Mar 3 17:34:39 2005
@@ -32,14 +32,22 @@
term_scorer_next_internal (lcn_scorer_t *scorer)
{
lcn_doc_iter_t *iter = scorer->baton;
+ lcn_boolean_t next;
- LCN_ERR (lcn_doc_iter_next (iter));
+ LCN_ERR (lcn_doc_iter_next (&next, iter));
- scorer->doc = lcn_doc_iter_doc (iter);
+ if (next)
+ {
+ scorer->doc = lcn_doc_iter_doc (iter);
- scorer->score = 1.0; /* XXX */
+ scorer->score = 1.0; /* XXX */
- return LCN_NO_ERROR;
+ return LCN_NO_ERROR;
+ }
+ else
+ {
+ return lcn_error_create (APR_EOF, NULL, "no more terms");
+ }
}
lcn_error_t *
Modified: incubator/lucene4c/trunk/test/index/index_test.c
URL:
http://svn.apache.org/viewcvs/incubator/lucene4c/trunk/test/index/index_test.c?view=diff&r1=156115&r2=156116
==============================================================================
--- incubator/lucene4c/trunk/test/index/index_test.c (original)
+++ incubator/lucene4c/trunk/test/index/index_test.c Thu Mar 3 17:34:39 2005
@@ -56,6 +56,7 @@
{
lcn_term_t *term = lcn_term_create_cstring ("lucene", "contents", p);
lcn_doc_iter_t *itr;
+ lcn_boolean_t next;
lcn_index_t *idx;
lcn_error_t *err;
int count = 0;
@@ -66,7 +67,7 @@
ABTS_INT_EQUAL (tc, 1, lcn_doc_iter_doc (itr));
- while ((err = lcn_doc_iter_next (itr)) == LCN_NO_ERROR)
+ while ((err = lcn_doc_iter_next (&next, itr)) == LCN_NO_ERROR && next)
{
if (++count == 1)
{
@@ -74,7 +75,7 @@
}
}
- ABTS_INT_EQUAL (tc, APR_EOF, err->apr_err);
+ ABTS_TRUE (tc, ! next);
ABTS_INT_EQUAL (tc, 75, count);
@@ -86,6 +87,7 @@
{
lcn_term_t *term = lcn_term_create_cstring ("lucene", "contents", p);
lcn_doc_iter_t *itr;
+ lcn_boolean_t next;
lcn_index_t *idx;
lcn_error_t *err;
int count = 0;
@@ -96,7 +98,7 @@
ABTS_INT_EQUAL (tc, 0, lcn_doc_iter_doc (itr));
- while ((err = lcn_doc_iter_next (itr)) == LCN_NO_ERROR)
+ while ((err = lcn_doc_iter_next (&next, itr)) == LCN_NO_ERROR && next)
{
if (++count == 1)
{
@@ -104,7 +106,7 @@
}
}
- ABTS_INT_EQUAL (tc, APR_EOF, err->apr_err);
+ ABTS_TRUE (tc, ! next);
ABTS_INT_EQUAL (tc, 487, count);
@@ -116,6 +118,7 @@
{
lcn_term_t *term = lcn_term_create_cstring ("erik", "contents", p);
lcn_doc_iter_t *itr;
+ lcn_boolean_t next;
lcn_index_t *idx;
lcn_error_t *err;
int count = 0;
@@ -126,7 +129,7 @@
ABTS_INT_EQUAL (tc, 125, lcn_doc_iter_doc (itr));
- while ((err = lcn_doc_iter_next (itr)) == LCN_NO_ERROR)
+ while ((err = lcn_doc_iter_next (&next, itr)) == LCN_NO_ERROR && next)
{
++count;
@@ -159,7 +162,7 @@
}
}
- ABTS_INT_EQUAL (tc, APR_EOF, err->apr_err);
+ ABTS_TRUE (tc, ! next);
ABTS_INT_EQUAL (tc, 7, count);