Skip to content

Commit

Permalink
Merge branch 'rebornix/buffer-pt'
Browse files Browse the repository at this point in the history
  • Loading branch information
rebornix committed Feb 9, 2018
2 parents 8e88f8c + 0051c12 commit 051d12b
Show file tree
Hide file tree
Showing 6 changed files with 289 additions and 69 deletions.
13 changes: 11 additions & 2 deletions src/vs/editor/common/model/indentationGuesser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,14 +97,23 @@ export function guessIndentation(source: ITextBuffer, defaultTabSize: number, de
let spacesDiffCount = [0, 0, 0, 0, 0, 0, 0, 0, 0]; // `tabSize` scores

for (let lineNumber = 1; lineNumber <= linesCount; lineNumber++) {
let currentLineLength = source.getLineLength(lineNumber);
let currentLineText = source.getLineContent(lineNumber);
let charCodeAt: (offset: number) => number;
if (currentLineLength > 65536) {
// if the text buffer is chunk based, so long lines are cons-string, v8 will flattern the string when we check charCode.
// checking charCode on chunks directly is cheaper.
charCodeAt = (offset: number) => source.getLineCharCode(lineNumber, offset);
} else {
charCodeAt = (offset: number) => currentLineText.charCodeAt(offset);
}

let currentLineHasContent = false; // does `currentLineText` contain non-whitespace chars
let currentLineIndentation = 0; // index at which `currentLineText` contains the first non-whitespace char
let currentLineSpacesCount = 0; // count of spaces found in `currentLineText` indentation
let currentLineTabsCount = 0; // count of tabs found in `currentLineText` indentation
for (let j = 0, lenJ = currentLineText.length; j < lenJ; j++) {
let charCode = currentLineText.charCodeAt(j);
for (let j = 0, lenJ = currentLineLength; j < lenJ; j++) {
let charCode = charCodeAt(j);

if (charCode === CharCode.Tab) {
currentLineTabsCount++;
Expand Down
Loading

0 comments on commit 051d12b

Please sign in to comment.