Do this special case search only when the array is large enough.

Otherwise the normal linear search should be sufficient.  Eventually
we need to use a better algorithm here than this special case handling...
This commit is contained in:
Kohei Yoshida
2012-04-11 15:36:00 -04:00
parent e981a10233
commit a78a7ee9f7

View File

@@ -688,7 +688,7 @@ size_t FastGetPos(const _Array& rArray, const _Val* p, size_t& rLastPos)
// Through certain filter code-paths we do a lot of appends, which in
// turn call GetPos - creating some N^2 nightmares. If we have a
// non-trivially large list, do a few checks from the end first.
if (rLastPos > 16)
if (rLastPos > 16 && nArrayLen > 16)
{
size_t nEnd;
if (rLastPos > nArrayLen - 2)
@@ -698,7 +698,7 @@ size_t FastGetPos(const _Array& rArray, const _Val* p, size_t& rLastPos)
for (size_t nIdx = rLastPos - 2; nIdx < nEnd; ++nIdx)
{
if (&rArray[nIdx] == p)
if (&rArray.at(nIdx) == p)
{
rLastPos = nIdx;
return nIdx;
@@ -707,7 +707,7 @@ size_t FastGetPos(const _Array& rArray, const _Val* p, size_t& rLastPos)
}
// The world's lamest linear search from svarray ...
for (size_t nIdx = 0; nIdx < nArrayLen; ++nIdx)
if (&rArray[nIdx] == p)
if (&rArray.at(nIdx) == p)
return rLastPos = nIdx;
// 0xFFFF is used to signify "not found" condition. We need to change this.