зеркало из https://github.com/mozilla/gecko-dev.git
Bug 917841 - Use overflow-resistant arithmetic in binary searches. r=luke
This commit is contained in:
Родитель
3d318d39ac
Коммит
cfa371035b
|
@ -216,7 +216,7 @@ TokenStream::SourceCoords::lineIndexOf(uint32_t offset) const
|
|||
// want one before that.
|
||||
iMax = lineStartOffsets_.length() - 2;
|
||||
while (iMax > iMin) {
|
||||
iMid = (iMin + iMax) / 2;
|
||||
iMid = iMin + (iMax - iMin) / 2;
|
||||
if (offset >= lineStartOffsets_[iMid + 1])
|
||||
iMin = iMid + 1; // offset is above lineStartOffsets_[iMid]
|
||||
else
|
||||
|
|
|
@ -467,14 +467,14 @@ BaselineScript::maybeICEntryFromReturnOffset(CodeOffsetLabel returnOffset)
|
|||
{
|
||||
size_t bottom = 0;
|
||||
size_t top = numICEntries();
|
||||
size_t mid = (bottom + top) / 2;
|
||||
size_t mid = bottom + (top - bottom) / 2;
|
||||
while (mid < top) {
|
||||
ICEntry &midEntry = icEntry(mid);
|
||||
if (midEntry.returnOffset().offset() < returnOffset.offset())
|
||||
bottom = mid + 1;
|
||||
else // if (midEntry.returnOffset().offset() >= returnOffset.offset())
|
||||
top = mid;
|
||||
mid = (bottom + top) / 2;
|
||||
mid = bottom + (top - bottom) / 2;
|
||||
}
|
||||
if (mid >= numICEntries())
|
||||
return NULL;
|
||||
|
@ -506,7 +506,7 @@ BaselineScript::icEntryFromPCOffset(uint32_t pcOffset)
|
|||
// those which have isForOp() set.
|
||||
size_t bottom = 0;
|
||||
size_t top = numICEntries();
|
||||
size_t mid = (bottom + top) / 2;
|
||||
size_t mid = bottom + (top - bottom) / 2;
|
||||
while (mid < top) {
|
||||
ICEntry &midEntry = icEntry(mid);
|
||||
if (midEntry.pcOffset() < pcOffset)
|
||||
|
@ -515,7 +515,7 @@ BaselineScript::icEntryFromPCOffset(uint32_t pcOffset)
|
|||
top = mid;
|
||||
else
|
||||
break;
|
||||
mid = (bottom + top) / 2;
|
||||
mid = bottom + (top - bottom) / 2;
|
||||
}
|
||||
// Found an IC entry with a matching PC offset. Search backward, and then
|
||||
// forward from this IC entry, looking for one with the same PC offset which
|
||||
|
|
|
@ -720,7 +720,7 @@ TypeScript::BytecodeTypes(JSScript *script, jsbytecode *pc)
|
|||
// Fall back to a binary search.
|
||||
size_t bottom = 0;
|
||||
size_t top = script->nTypeSets - 1;
|
||||
size_t mid = (bottom + top) / 2;
|
||||
size_t mid = bottom + (top - bottom) / 2;
|
||||
while (mid < top) {
|
||||
if (bytecodeMap[mid] < offset)
|
||||
bottom = mid + 1;
|
||||
|
@ -728,7 +728,7 @@ TypeScript::BytecodeTypes(JSScript *script, jsbytecode *pc)
|
|||
top = mid;
|
||||
else
|
||||
break;
|
||||
mid = (bottom + top) / 2;
|
||||
mid = bottom + (top - bottom) / 2;
|
||||
}
|
||||
|
||||
// We should have have zeroed in on either the exact offset, unless there
|
||||
|
|
Загрузка…
Ссылка в новой задаче