The utility semantics::SemanticsContext::FindScope() maps a contiguous range of cooked source characters to the innermost Scope containing them. Its implementation is unacceptably slow on large (tens of thousands of lines) source files with many program units; it traverses each level of the scope tree linearly. Replace this implementation with a single instance of std::multimap<> used as an index from each Scope's source range back to the Scope. Compilation time with "-fsyntax-only" on the 50,000-line test case that motivated this change drops from 4.36s to 3.72s, and FindScope() no longer stands out egregiously in the profile. Differential Revision: https://reviews.llvm.org/D159027
15 KiB
15 KiB