diff options
author | Fangrui Song <maskray@google.com> | 2019-06-21 05:40:31 +0000 |
---|---|---|
committer | Fangrui Song <maskray@google.com> | 2019-06-21 05:40:31 +0000 |
commit | dc8de6037c3aceb9663c7433bb09584fa8571032 (patch) | |
tree | acb49acaa3d1a0428951451a091fcb4d0c79a464 /llvm/lib/Support | |
parent | d5e1ce3f44b0bef1eadbef9828b87a8918a82669 (diff) | |
download | bcm5719-llvm-dc8de6037c3aceb9663c7433bb09584fa8571032.tar.gz bcm5719-llvm-dc8de6037c3aceb9663c7433bb09584fa8571032.zip |
Simplify std::lower_bound with llvm::{bsearch,lower_bound}. NFC
llvm-svn: 364006
Diffstat (limited to 'llvm/lib/Support')
-rw-r--r-- | llvm/lib/Support/SourceMgr.cpp | 11 |
1 files changed, 3 insertions, 8 deletions
diff --git a/llvm/lib/Support/SourceMgr.cpp b/llvm/lib/Support/SourceMgr.cpp index 401f6aec4ca..2a241f18c36 100644 --- a/llvm/lib/Support/SourceMgr.cpp +++ b/llvm/lib/Support/SourceMgr.cpp @@ -95,14 +95,9 @@ unsigned SourceMgr::SrcBuffer::getLineNumber(const char *Ptr) const { assert(PtrDiff >= 0 && static_cast<size_t>(PtrDiff) <= std::numeric_limits<T>::max()); T PtrOffset = static_cast<T>(PtrDiff); - // std::lower_bound returns the first EOL offset that's not-less-than - // PtrOffset, meaning the EOL that _ends the line_ that PtrOffset is on - // (including if PtrOffset refers to the EOL itself). If there's no such - // EOL, returns end(). - auto EOL = std::lower_bound(Offsets->begin(), Offsets->end(), PtrOffset); - - // Lines count from 1, so add 1 to the distance from the 0th line. - return (1 + (EOL - Offsets->begin())); + // llvm::lower_bound gives the number of EOL before PtrOffset. Add 1 to get + // the line number. + return llvm::lower_bound(*Offsets, PtrOffset) - Offsets->begin() + 1; } SourceMgr::SrcBuffer::SrcBuffer(SourceMgr::SrcBuffer &&Other) |