Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Speed up _parseWords further #173050

Merged
merged 1 commit into from
Feb 1, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/

import { escapeRegExpCharacters } from 'vs/base/common/strings';
import { URI } from 'vs/base/common/uri';
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
import { matchesScheme } from 'vs/platform/opener/common/opener';
Expand Down Expand Up @@ -33,7 +34,7 @@ export class TerminalWordLinkDetector implements ITerminalLinkDetector {
// quite small.
readonly maxLinkLength = 100;

private _separatorCodes!: Uint32Array;
private _separatorRegex!: RegExp;

constructor(
readonly xterm: Terminal,
Expand Down Expand Up @@ -108,26 +109,21 @@ export class TerminalWordLinkDetector implements ITerminalLinkDetector {

private _parseWords(text: string): Word[] {
const words: Word[] = [];

let startIndex = 0;
for (let i = 0; i < text.length; i++) {
if (this._separatorCodes.includes(text.charCodeAt(i))) {
words.push({ startIndex, endIndex: i, text: text.substring(startIndex, i) });
startIndex = i + 1;
}
}
if (startIndex < text.length) {
words.push({ startIndex, endIndex: text.length, text: text.substring(startIndex) });
const splitWords = text.split(this._separatorRegex);
let runningIndex = 0;
for (let i = 0; i < splitWords.length; i++) {
words.push({
text: splitWords[i],
startIndex: runningIndex,
endIndex: runningIndex + splitWords[i].length
});
runningIndex += splitWords[i].length + 1;
}

return words;
}

private _refreshSeparatorCodes(): void {
const separators = this._configurationService.getValue<ITerminalConfiguration>(TERMINAL_CONFIG_SECTION).wordSeparators;
this._separatorCodes = new Uint32Array(separators.length);
for (let i = 0; i < separators.length; i++) {
this._separatorCodes[i] = separators.charCodeAt(i);
}
this._separatorRegex = new RegExp(`[${escapeRegExpCharacters(separators)}]`, 'g');
}
}