More performant lookup for line number
This commit is contained in:
parent
2b248101d5
commit
faa9300132
|
@ -40,30 +40,19 @@ Diagnostic *DiagnosticsHolder::GetDiagnosticAt(int position) {
|
|||
}
|
||||
|
||||
size_t DiagnosticsHolder::GetLineFromPosition(size_t i) {
|
||||
size_t topLimit = _lineStarts.size() - 1;
|
||||
size_t bottomLimit = 0;
|
||||
while (true){
|
||||
if (bottomLimit == topLimit){
|
||||
return bottomLimit;
|
||||
}
|
||||
size_t half = bottomLimit + ((topLimit - bottomLimit) / 2);
|
||||
size_t pos = _lineStarts[half];
|
||||
size_t length = _lineLength[half];
|
||||
if (pos < i && pos + length > i){
|
||||
return half;
|
||||
}
|
||||
size_t topLimit = _lineStarts.size() - 1;
|
||||
while (bottomLimit <= topLimit){
|
||||
size_t index = bottomLimit + (topLimit - bottomLimit) / 2;
|
||||
auto pos = _lineStarts[index];
|
||||
if (pos == i) return index;
|
||||
if (pos > i){
|
||||
topLimit = half;
|
||||
} else if (pos < i){
|
||||
if (bottomLimit == half){
|
||||
bottomLimit = half + 1;
|
||||
} else{
|
||||
bottomLimit = half;
|
||||
}
|
||||
topLimit = index - 1;
|
||||
} else{
|
||||
return half;
|
||||
bottomLimit = index + 1;
|
||||
}
|
||||
}
|
||||
return bottomLimit - 1;
|
||||
}
|
||||
|
||||
std::string SeverityToString(DiagnosticSeverity s){
|
||||
|
|
Loading…
Reference in New Issue