[cfe-commits] [PATCH] Optimize SourceManager::getColumnNumber to fix PR14106

Douglas Gregor dgregor at apple.com
Thu Oct 18 09:43:56 PDT 2012


On Oct 17, 2012, at 6:04 PM, Craig Topper <craig.topper at gmail.com> wrote:

> This patch uses the line number cache to find the start of the line instead of searching backwards for it. This helps performance in cases where the line is long and have just called getLineNumber for the same position.

This only helps when the FilePos is exactly the same as the FilePos that went to getLineNumber:

+  // See if we just calculated the line number for this FilePos and can use
+  // that to lookup the start of the line instead of searching for it.
+  if (LastLineNoFileIDQuery == FID && LastLineNoFilePos == (FilePos + 1)) {

Why not simply check that FilePos > SourceLineCache[LastLineNoResult - 1] and < SourceLineCache[LastLineNoResult], so anything on the most-recently-queried line can be handled efficiently?

	- Doug




More information about the cfe-commits mailing list