[clang] [clang] Improve getFileIDLocal binary search. (PR #146510)
Erich Keane via cfe-commits
cfe-commits at lists.llvm.org
Tue Jul 1 06:33:26 PDT 2025
================
@@ -855,35 +857,24 @@ FileID SourceManager::getFileIDLocal(SourceLocation::UIntTy SLocOffset) const {
break;
}
- NumProbes = 0;
- while (true) {
- unsigned MiddleIndex = (GreaterIndex-LessIndex)/2+LessIndex;
- SourceLocation::UIntTy MidOffset =
- getLocalSLocEntry(MiddleIndex).getOffset();
-
- ++NumProbes;
-
- // If the offset of the midpoint is too large, chop the high side of the
- // range to the midpoint.
- if (MidOffset > SLocOffset) {
- GreaterIndex = MiddleIndex;
- continue;
- }
+ while (LessIndex < GreaterIndex) {
----------------
erichkeane wrote:
Trying to learn this function myself... I was wondering : Did you do any benchmarking/etc on the linear search above? Wonder if there is more perf to be grabbed out of it.
https://github.com/llvm/llvm-project/pull/146510
More information about the cfe-commits
mailing list