зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1542106
- Cache the last (line number, offset => column) mapping returned and use it to optimize a subsequent lookup that's further along in the same line. r=arai
Differential Revision: https://phabricator.services.mozilla.com/D26270 --HG-- extra : moz-landing-system : lando
This commit is contained in:
Родитель
5327fe7f3e
Коммит
b2ffd2f110
|
@ -690,11 +690,26 @@ uint32_t GeneralTokenStreamChars<Unit, AnyCharsAccess>::computeColumn(
|
|||
|
||||
const TokenStreamAnyChars& anyChars = anyCharsAccess();
|
||||
|
||||
const Unit* begin =
|
||||
this->sourceUnits.codeUnitPtrAt(anyChars.lineStart(lineToken));
|
||||
uint32_t lineNumber = anyChars.srcCoords.lineNumber(lineToken);
|
||||
|
||||
uint32_t beginOffset;
|
||||
uint32_t partialCols;
|
||||
if (lineNumber == lastLineForColumn_ && lastOffsetForColumn_ <= offset) {
|
||||
beginOffset = lastOffsetForColumn_;
|
||||
partialCols = lastColumn_;
|
||||
} else {
|
||||
beginOffset = anyChars.lineStart(lineToken);
|
||||
partialCols = 0;
|
||||
}
|
||||
|
||||
const Unit* begin = this->sourceUnits.codeUnitPtrAt(beginOffset);
|
||||
const Unit* end = this->sourceUnits.codeUnitPtrAt(offset);
|
||||
|
||||
auto partialCols = AssertedCast<uint32_t>(ComputeColumn(begin, end));
|
||||
partialCols += AssertedCast<uint32_t>(ComputeColumn(begin, end));
|
||||
|
||||
lastLineForColumn_ = lineNumber;
|
||||
lastOffsetForColumn_ = offset;
|
||||
lastColumn_ = partialCols;
|
||||
return (lineToken.isFirstLine() ? anyChars.options_.column : 0) + partialCols;
|
||||
}
|
||||
|
||||
|
|
|
@ -1941,6 +1941,22 @@ class GeneralTokenStreamChars : public SpecializedTokenStreamCharsBase<Unit> {
|
|||
return static_cast<TokenStreamSpecific*>(this);
|
||||
}
|
||||
|
||||
private:
|
||||
// Computing accurate column numbers requires linearly iterating through all
|
||||
// source units in the line to account for multi-unit code points; on long
|
||||
// lines requiring many column computations, this becomes quadratic.
|
||||
//
|
||||
// However, because usually we need columns for advancing offsets through
|
||||
// scripts, caching the last ((line number, offset) => relative column)
|
||||
// mapping -- in similar manner to how |SourceUnits::lastIndex_| is used to
|
||||
// cache (offset => line number) mappings -- lets us avoid re-iterating
|
||||
// through the line prefix in most cases.
|
||||
|
||||
mutable uint32_t lastLineForColumn_ = UINT32_MAX;
|
||||
mutable uint32_t lastOffsetForColumn_ = UINT32_MAX;
|
||||
mutable uint32_t lastColumn_ = 0;
|
||||
|
||||
protected:
|
||||
uint32_t computeColumn(LineToken lineToken, uint32_t offset) const;
|
||||
void computeLineAndColumn(uint32_t offset, uint32_t* line,
|
||||
uint32_t* column) const;
|
||||
|
|
Загрузка…
Ссылка в новой задаче