llvm-project
72af17eb - [Support] Faster line and column lookup in SourceMgr (#195881)

Commit
3 days ago
[Support] Faster line and column lookup in SourceMgr (#195881) Previously line and column lookup worked by finding the line number by utilizing a cache of offsets of line ends. And finding the column number by linear search of a previous newline. This is quite slow and caused some issues after merging #174566 and was fixed by wrapping all calls of the slow function in a `if (ParserContext)` in #180068. This is not ideal, since when the parser context would be supplied the parsing of files with long lines will take ages. This PR implements a fix to the problem by utilizing the computed offsets for line ends to calculate the position on the current line. Thus improving the asymptotic complexity of the getLineAndColumn method from O(log l + c) to O(log l) (l is number of lines, c is column position of the pointer). While not adding any overhead. The second commit in this PR just updates two comments that I thought were misleading. Since the getLineNumber methods are now unused I removed them in the third commit. And that caused MLIR to not compile, so I fixed it, while removing TODOs, that are implemented by this PR.
Author
Parents
Loading