Skip to content

Commit

Permalink
Merge pull request #3844 from Xinok/issue15385
Browse files Browse the repository at this point in the history
Fix Issue 15385 - SortedRange.contains() optimize predicate calls
  • Loading branch information
MartinNowak committed Nov 30, 2015
2 parents 40b2e45 + dda21ec commit 4a12bd6
Showing 1 changed file with 4 additions and 22 deletions.
26 changes: 4 additions & 22 deletions std/range/package.d
Expand Up @@ -7833,28 +7833,10 @@ sgi.com/tech/stl/binary_search.html, binary_search).
bool contains(V)(V value)
if (isRandomAccessRange!Range)
{
size_t first = 0, count = _input.length;
while (count > 0)
{
immutable step = count / 2, it = first + step;
if (predFun(_input[it], value))
{
// Less than value, bump left bound up
first = it + 1;
count -= step + 1;
}
else if (predFun(value, _input[it]))
{
// Greater than value, chop count
count = step;
}
else
{
// Found!!!
return true;
}
}
return false;
if(empty) return false;
immutable i = getTransitionIndex!(SearchPolicy.binarySearch, geq)(value);
if(i >= length) return false;
return !predFun(value, _input[i]);
}

// groupBy
Expand Down

0 comments on commit 4a12bd6

Please sign in to comment.