mirror of
https://git.kernel.org/pub/scm/fs/ext2/e2fsprogs.git
synced 2024-12-11 19:03:40 +08:00
e2fsck: simplify binary search in ea_refcount.c
Remove the interpolation search in ea_refcount. The added complexity isn't worth the speed up. Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
This commit is contained in:
parent
b1c828e875
commit
8c0de61a24
@ -155,9 +155,7 @@ static struct ea_refcount_el *insert_refcount_el(ext2_refcount_t refcount,
|
||||
static struct ea_refcount_el *get_refcount_el(ext2_refcount_t refcount,
|
||||
blk_t blk, int create)
|
||||
{
|
||||
float range;
|
||||
int low, high, mid;
|
||||
blk_t lowval, highval;
|
||||
|
||||
if (!refcount || !refcount->list)
|
||||
return 0;
|
||||
@ -183,31 +181,7 @@ retry:
|
||||
printf("Non-cursor get_refcount_el: %u\n", blk);
|
||||
#endif
|
||||
while (low <= high) {
|
||||
#if 0
|
||||
mid = (low+high)/2;
|
||||
#else
|
||||
if (low == high)
|
||||
mid = low;
|
||||
else {
|
||||
/* Interpolate for efficiency */
|
||||
lowval = refcount->list[low].ea_blk;
|
||||
highval = refcount->list[high].ea_blk;
|
||||
|
||||
if (blk < lowval)
|
||||
range = 0;
|
||||
else if (blk > highval)
|
||||
range = 1;
|
||||
else {
|
||||
range = ((float) (blk - lowval)) /
|
||||
(highval - lowval);
|
||||
if (range > 0.9)
|
||||
range = 0.9;
|
||||
if (range < 0.1)
|
||||
range = 0.1;
|
||||
}
|
||||
mid = low + ((int) (range * (high-low)));
|
||||
}
|
||||
#endif
|
||||
if (blk == refcount->list[mid].ea_blk) {
|
||||
refcount->cursor = mid+1;
|
||||
return &refcount->list[mid];
|
||||
|
Loading…
Reference in New Issue
Block a user