Commit 05545312 authored by Tim Peters's avatar Tim Peters

BTreeItems_seek(): Simplify the use of persistence macros. This routine

is now almost as simple as it's been trying to be <wink>.
parent 9a217f76
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
****************************************************************************/ ****************************************************************************/
#define BTREEITEMSTEMPLATE_C "$Id: BTreeItemsTemplate.c,v 1.15 2002/06/18 02:26:19 tim_one Exp $\n" #define BTREEITEMSTEMPLATE_C "$Id: BTreeItemsTemplate.c,v 1.16 2002/06/18 02:41:26 tim_one Exp $\n"
/* A BTreeItems struct is returned from calling .items(), .keys() or /* A BTreeItems struct is returned from calling .items(), .keys() or
* .values() on a BTree-based data structure, and is also the result of * .values() on a BTree-based data structure, and is also the result of
...@@ -157,32 +157,27 @@ BTreeItems_seek(BTreeItems *self, int i) ...@@ -157,32 +157,27 @@ BTreeItems_seek(BTreeItems *self, int i)
pseudoindex = -1; pseudoindex = -1;
} }
PER_USE_OR_RETURN(currentbucket, -1);
delta = i - pseudoindex; delta = i - pseudoindex;
while (delta > 0) { /* move right */ while (delta > 0) { /* move right */
int max; int max;
/* Want to move right delta positions; the most we can move right in /* Want to move right delta positions; the most we can move right in
* this bucket is currentbucket->len - currentoffset - 1 positions. * this bucket is currentbucket->len - currentoffset - 1 positions.
*/ */
PER_USE_OR_RETURN(currentbucket, -1);
max = currentbucket->len - currentoffset - 1; max = currentbucket->len - currentoffset - 1;
b = currentbucket->next;
PER_ALLOW_DEACTIVATION(currentbucket);
PER_ACCESSED(currentbucket);
if (delta <= max) { if (delta <= max) {
currentoffset += delta; currentoffset += delta;
pseudoindex += delta; pseudoindex += delta;
if (currentbucket == self->lastbucket if (currentbucket == self->lastbucket
&& currentoffset > self->last) { && currentoffset > self->last) goto no_match;
PER_ALLOW_DEACTIVATION(currentbucket);
PER_ACCESSED(currentbucket);
goto no_match;
}
break; break;
} }
/* Move to start of next bucket. */ /* Move to start of next bucket. */
b = currentbucket->next;
PER_ALLOW_DEACTIVATION(currentbucket);
PER_ACCESSED(currentbucket);
if (currentbucket == self->lastbucket || b == NULL) goto no_match; if (currentbucket == self->lastbucket || b == NULL) goto no_match;
currentbucket = b; currentbucket = b;
PER_USE_OR_RETURN(currentbucket, -1);
pseudoindex += max + 1; pseudoindex += max + 1;
delta -= max + 1; delta -= max + 1;
currentoffset = 0; currentoffset = 0;
...@@ -196,29 +191,23 @@ BTreeItems_seek(BTreeItems *self, int i) ...@@ -196,29 +191,23 @@ BTreeItems_seek(BTreeItems *self, int i)
currentoffset += delta; currentoffset += delta;
pseudoindex += delta; pseudoindex += delta;
if (currentbucket == self->firstbucket if (currentbucket == self->firstbucket
&& currentoffset < self->first) { && currentoffset < self->first) goto no_match;
PER_ALLOW_DEACTIVATION(currentbucket);
PER_ACCESSED(currentbucket);
goto no_match;
}
break; break;
} }
/* Move to end of previous bucket. */ /* Move to end of previous bucket. */
PER_ALLOW_DEACTIVATION(currentbucket);
PER_ACCESSED(currentbucket);
if (currentbucket == self->firstbucket) goto no_match; if (currentbucket == self->firstbucket) goto no_match;
status = PreviousBucket(&currentbucket, self->firstbucket); status = PreviousBucket(&currentbucket, self->firstbucket);
if (status == 0) if (status == 0)
goto no_match; goto no_match;
else if (status < 0) else if (status < 0)
return -1; return -1;
PER_USE_OR_RETURN(currentbucket, -1);
pseudoindex -= currentoffset + 1; pseudoindex -= currentoffset + 1;
delta += currentoffset + 1; delta += currentoffset + 1;
PER_USE_OR_RETURN(currentbucket, -1);
currentoffset = currentbucket->len - 1; currentoffset = currentbucket->len - 1;
}
PER_ALLOW_DEACTIVATION(currentbucket); PER_ALLOW_DEACTIVATION(currentbucket);
PER_ACCESSED(currentbucket); PER_ACCESSED(currentbucket);
}
assert(pseudoindex == i); assert(pseudoindex == i);
Py_INCREF(currentbucket); Py_INCREF(currentbucket);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment