mirror of
https://github.com/Microsoft/vscode
synced 2024-08-28 05:19:39 +00:00
Remove stringbuilder code for when TextDecoder
doesn't exist (#157952)
All of the environments we run in now have `TextDecoder`
This commit is contained in:
parent
087921e04a
commit
6958e011d2
|
@ -5,7 +5,7 @@
|
|||
|
||||
import { WrappingIndent } from 'vs/editor/common/config/editorOptions';
|
||||
import { FontInfo } from 'vs/editor/common/config/fontInfo';
|
||||
import { createStringBuilder, IStringBuilder } from 'vs/editor/common/core/stringBuilder';
|
||||
import { StringBuilder } from 'vs/editor/common/core/stringBuilder';
|
||||
import { CharCode } from 'vs/base/common/charCode';
|
||||
import * as strings from 'vs/base/common/strings';
|
||||
import { applyFontInfo } from 'vs/editor/browser/config/domFontInfo';
|
||||
|
@ -72,7 +72,7 @@ function createLineBreaks(requests: string[], fontInfo: FontInfo, tabSize: numbe
|
|||
const containerDomNode = document.createElement('div');
|
||||
applyFontInfo(containerDomNode, fontInfo);
|
||||
|
||||
const sb = createStringBuilder(10000);
|
||||
const sb = new StringBuilder(10000);
|
||||
const firstNonWhitespaceIndices: number[] = [];
|
||||
const wrappedTextIndentLengths: number[] = [];
|
||||
const renderLineContents: string[] = [];
|
||||
|
@ -182,7 +182,7 @@ const enum Constants {
|
|||
SPAN_MODULO_LIMIT = 16384
|
||||
}
|
||||
|
||||
function renderLine(lineContent: string, initialVisibleColumn: number, tabSize: number, width: number, sb: IStringBuilder, wrappingIndentLength: number): [number[], number[]] {
|
||||
function renderLine(lineContent: string, initialVisibleColumn: number, tabSize: number, width: number, sb: StringBuilder, wrappingIndentLength: number): [number[], number[]] {
|
||||
|
||||
if (wrappingIndentLength !== 0) {
|
||||
const hangingOffset = String(wrappingIndentLength);
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import { FastDomNode, createFastDomNode } from 'vs/base/browser/fastDomNode';
|
||||
import { IStringBuilder, createStringBuilder } from 'vs/editor/common/core/stringBuilder';
|
||||
import { StringBuilder } from 'vs/editor/common/core/stringBuilder';
|
||||
import * as viewEvents from 'vs/editor/common/viewEvents';
|
||||
import { ViewportData } from 'vs/editor/common/viewLayout/viewLinesViewportData';
|
||||
import { EditorOption } from 'vs/editor/common/config/editorOptions';
|
||||
|
@ -20,7 +20,7 @@ export interface IVisibleLine extends ILine {
|
|||
* Return null if the HTML should not be touched.
|
||||
* Return the new HTML otherwise.
|
||||
*/
|
||||
renderLine(lineNumber: number, deltaTop: number, viewportData: ViewportData, sb: IStringBuilder): boolean;
|
||||
renderLine(lineNumber: number, deltaTop: number, viewportData: ViewportData, sb: StringBuilder): boolean;
|
||||
|
||||
/**
|
||||
* Layout the line.
|
||||
|
@ -547,7 +547,7 @@ class ViewLayerRenderer<T extends IVisibleLine> {
|
|||
}
|
||||
}
|
||||
|
||||
private static readonly _sb = createStringBuilder(100000);
|
||||
private static readonly _sb = new StringBuilder(100000);
|
||||
|
||||
private _finishRendering(ctx: IRendererContext<T>, domNodeIsEmpty: boolean, deltaTop: number[]): void {
|
||||
|
||||
|
|
|
@ -8,7 +8,7 @@ import { applyFontInfo } from 'vs/editor/browser/config/domFontInfo';
|
|||
import { DynamicViewOverlay } from 'vs/editor/browser/view/dynamicViewOverlay';
|
||||
import { IVisibleLine, IVisibleLinesHost, VisibleLinesCollection } from 'vs/editor/browser/view/viewLayer';
|
||||
import { ViewPart } from 'vs/editor/browser/view/viewPart';
|
||||
import { IStringBuilder } from 'vs/editor/common/core/stringBuilder';
|
||||
import { StringBuilder } from 'vs/editor/common/core/stringBuilder';
|
||||
import { IEditorConfiguration } from 'vs/editor/common/config/editorConfiguration';
|
||||
import { RenderingContext, RestrictedRenderingContext } from 'vs/editor/browser/view/renderingContext';
|
||||
import { ViewContext } from 'vs/editor/common/viewModel/viewContext';
|
||||
|
@ -175,7 +175,7 @@ export class ViewOverlayLine implements IVisibleLine {
|
|||
this._lineHeight = this._configuration.options.get(EditorOption.lineHeight);
|
||||
}
|
||||
|
||||
public renderLine(lineNumber: number, deltaTop: number, viewportData: ViewportData, sb: IStringBuilder): boolean {
|
||||
public renderLine(lineNumber: number, deltaTop: number, viewportData: ViewportData, sb: StringBuilder): boolean {
|
||||
let result = '';
|
||||
for (let i = 0, len = this._dynamicOverlays.length; i < len; i++) {
|
||||
const dynamicOverlay = this._dynamicOverlays[i];
|
||||
|
|
|
@ -8,7 +8,7 @@ import { FastDomNode, createFastDomNode } from 'vs/base/browser/fastDomNode';
|
|||
import * as platform from 'vs/base/common/platform';
|
||||
import { IVisibleLine } from 'vs/editor/browser/view/viewLayer';
|
||||
import { RangeUtil } from 'vs/editor/browser/viewParts/lines/rangeUtil';
|
||||
import { IStringBuilder } from 'vs/editor/common/core/stringBuilder';
|
||||
import { StringBuilder } from 'vs/editor/common/core/stringBuilder';
|
||||
import { IEditorConfiguration } from 'vs/editor/common/config/editorConfiguration';
|
||||
import { FloatHorizontalRange, VisibleRanges } from 'vs/editor/browser/view/renderingContext';
|
||||
import { LineDecoration } from 'vs/editor/common/viewLayout/lineDecorations';
|
||||
|
@ -186,7 +186,7 @@ export class ViewLine implements IVisibleLine {
|
|||
return false;
|
||||
}
|
||||
|
||||
public renderLine(lineNumber: number, deltaTop: number, viewportData: ViewportData, sb: IStringBuilder): boolean {
|
||||
public renderLine(lineNumber: number, deltaTop: number, viewportData: ViewportData, sb: StringBuilder): boolean {
|
||||
if (this._isMaybeInvalid === false) {
|
||||
// it appears that nothing relevant has changed
|
||||
return false;
|
||||
|
|
|
@ -24,7 +24,7 @@ import { IDiffEditorOptions, EditorLayoutInfo, EditorOption, EditorOptions, Edit
|
|||
import { IPosition, Position } from 'vs/editor/common/core/position';
|
||||
import { IRange, Range } from 'vs/editor/common/core/range';
|
||||
import { ISelection, Selection } from 'vs/editor/common/core/selection';
|
||||
import { IStringBuilder, createStringBuilder } from 'vs/editor/common/core/stringBuilder';
|
||||
import { StringBuilder } from 'vs/editor/common/core/stringBuilder';
|
||||
import * as editorCommon from 'vs/editor/common/editorCommon';
|
||||
import { IModelDecorationsChangeAccessor, IModelDeltaDecoration, ITextModel } from 'vs/editor/common/model';
|
||||
import { ModelDecorationOptions } from 'vs/editor/common/model/textModel';
|
||||
|
@ -2479,7 +2479,7 @@ class InlineViewZonesComputer extends ViewZonesComputer {
|
|||
}
|
||||
const hasCharChanges = (decorations.length > 0);
|
||||
|
||||
const sb = createStringBuilder(10000);
|
||||
const sb = new StringBuilder(10000);
|
||||
let maxCharsPerLine = 0;
|
||||
let renderedLineCount = 0;
|
||||
let viewLineCounts: number[] | null = null;
|
||||
|
@ -2597,7 +2597,7 @@ class InlineViewZonesComputer extends ViewZonesComputer {
|
|||
renderControlCharacters: boolean,
|
||||
fontLigatures: string,
|
||||
tabSize: number,
|
||||
sb: IStringBuilder,
|
||||
sb: StringBuilder,
|
||||
marginDomNode: HTMLElement
|
||||
): number {
|
||||
|
||||
|
|
|
@ -7,22 +7,6 @@ import * as strings from 'vs/base/common/strings';
|
|||
import * as platform from 'vs/base/common/platform';
|
||||
import * as buffer from 'vs/base/common/buffer';
|
||||
|
||||
declare const TextDecoder: {
|
||||
prototype: TextDecoder;
|
||||
new(label?: string): TextDecoder;
|
||||
};
|
||||
interface TextDecoder {
|
||||
decode(view: Uint16Array): string;
|
||||
}
|
||||
|
||||
export interface IStringBuilder {
|
||||
build(): string;
|
||||
reset(): void;
|
||||
write1(charCode: number): void;
|
||||
appendASCII(charCode: number): void;
|
||||
appendASCIIString(str: string): void;
|
||||
}
|
||||
|
||||
let _utf16LE_TextDecoder: TextDecoder | null;
|
||||
function getUTF16LE_TextDecoder(): TextDecoder {
|
||||
if (!_utf16LE_TextDecoder) {
|
||||
|
@ -47,19 +31,7 @@ export function getPlatformTextDecoder(): TextDecoder {
|
|||
return _platformTextDecoder;
|
||||
}
|
||||
|
||||
export const hasTextDecoder = (typeof TextDecoder !== 'undefined');
|
||||
export let createStringBuilder: (capacity: number) => IStringBuilder;
|
||||
export let decodeUTF16LE: (source: Uint8Array, offset: number, len: number) => string;
|
||||
|
||||
if (hasTextDecoder) {
|
||||
createStringBuilder = (capacity) => new StringBuilder(capacity);
|
||||
decodeUTF16LE = standardDecodeUTF16LE;
|
||||
} else {
|
||||
createStringBuilder = (capacity) => new CompatStringBuilder();
|
||||
decodeUTF16LE = compatDecodeUTF16LE;
|
||||
}
|
||||
|
||||
function standardDecodeUTF16LE(source: Uint8Array, offset: number, len: number): string {
|
||||
export function decodeUTF16LE(source: Uint8Array, offset: number, len: number): string {
|
||||
const view = new Uint16Array(source.buffer, offset, len);
|
||||
if (len > 0 && (view[0] === 0xFEFF || view[0] === 0xFFFE)) {
|
||||
// UTF16 sometimes starts with a BOM https://de.wikipedia.org/wiki/Byte_Order_Mark
|
||||
|
@ -81,7 +53,7 @@ function compatDecodeUTF16LE(source: Uint8Array, offset: number, len: number): s
|
|||
return result.join('');
|
||||
}
|
||||
|
||||
class StringBuilder implements IStringBuilder {
|
||||
export class StringBuilder {
|
||||
|
||||
private readonly _capacity: number;
|
||||
private readonly _buffer: Uint16Array;
|
||||
|
@ -166,35 +138,3 @@ class StringBuilder implements IStringBuilder {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
class CompatStringBuilder implements IStringBuilder {
|
||||
|
||||
private _pieces: string[];
|
||||
private _piecesLen: number;
|
||||
|
||||
constructor() {
|
||||
this._pieces = [];
|
||||
this._piecesLen = 0;
|
||||
}
|
||||
|
||||
public reset(): void {
|
||||
this._pieces = [];
|
||||
this._piecesLen = 0;
|
||||
}
|
||||
|
||||
public build(): string {
|
||||
return this._pieces.join('');
|
||||
}
|
||||
|
||||
public write1(charCode: number): void {
|
||||
this._pieces[this._piecesLen++] = String.fromCharCode(charCode);
|
||||
}
|
||||
|
||||
public appendASCII(charCode: number): void {
|
||||
this._pieces[this._piecesLen++] = String.fromCharCode(charCode);
|
||||
}
|
||||
|
||||
public appendASCIIString(str: string): void {
|
||||
this._pieces[this._piecesLen++] = str;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -416,22 +416,13 @@ function createBracketOrRegExp(pieces: string[]): RegExp {
|
|||
const toReversedString = (function () {
|
||||
|
||||
function reverse(str: string): string {
|
||||
if (stringBuilder.hasTextDecoder) {
|
||||
// create a Uint16Array and then use a TextDecoder to create a string
|
||||
const arr = new Uint16Array(str.length);
|
||||
let offset = 0;
|
||||
for (let i = str.length - 1; i >= 0; i--) {
|
||||
arr[offset++] = str.charCodeAt(i);
|
||||
}
|
||||
return stringBuilder.getPlatformTextDecoder().decode(arr);
|
||||
} else {
|
||||
const result: string[] = [];
|
||||
let resultLen = 0;
|
||||
for (let i = str.length - 1; i >= 0; i--) {
|
||||
result[resultLen++] = str.charAt(i);
|
||||
}
|
||||
return result.join('');
|
||||
// create a Uint16Array and then use a TextDecoder to create a string
|
||||
const arr = new Uint16Array(str.length);
|
||||
let offset = 0;
|
||||
for (let i = str.length - 1; i >= 0; i--) {
|
||||
arr[offset++] = str.charCodeAt(i);
|
||||
}
|
||||
return stringBuilder.getPlatformTextDecoder().decode(arr);
|
||||
}
|
||||
|
||||
let lastInput: string | null = null;
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
import { CharCode } from 'vs/base/common/charCode';
|
||||
import * as strings from 'vs/base/common/strings';
|
||||
import { IViewLineTokens } from 'vs/editor/common/tokens/lineTokens';
|
||||
import { IStringBuilder, createStringBuilder } from 'vs/editor/common/core/stringBuilder';
|
||||
import { StringBuilder } from 'vs/editor/common/core/stringBuilder';
|
||||
import { LineDecoration, LineDecorationsNormalizer } from 'vs/editor/common/viewLayout/lineDecorations';
|
||||
import { InlineDecorationType } from 'vs/editor/common/viewModel';
|
||||
import { LinePart, LinePartMetadata } from 'vs/editor/common/viewLayout/linePart';
|
||||
|
@ -348,7 +348,7 @@ export class RenderLineOutput {
|
|||
}
|
||||
}
|
||||
|
||||
export function renderViewLine(input: RenderLineInput, sb: IStringBuilder): RenderLineOutput {
|
||||
export function renderViewLine(input: RenderLineInput, sb: StringBuilder): RenderLineOutput {
|
||||
if (input.lineContent.length === 0) {
|
||||
|
||||
if (input.lineDecorations.length > 0) {
|
||||
|
@ -410,7 +410,7 @@ export class RenderLineOutput2 {
|
|||
}
|
||||
|
||||
export function renderViewLine2(input: RenderLineInput): RenderLineOutput2 {
|
||||
const sb = createStringBuilder(10000);
|
||||
const sb = new StringBuilder(10000);
|
||||
const out = renderViewLine(input, sb);
|
||||
return new RenderLineOutput2(out.characterMapping, sb.build(), out.containsRTL, out.containsForeignElements);
|
||||
}
|
||||
|
@ -904,7 +904,7 @@ function _applyInlineDecorations(lineContent: string, len: number, tokens: LineP
|
|||
* This function is on purpose not split up into multiple functions to allow runtime type inference (i.e. performance reasons).
|
||||
* Notice how all the needed data is fully resolved and passed in (i.e. no other calls).
|
||||
*/
|
||||
function _renderLine(input: ResolvedRenderLineInput, sb: IStringBuilder): RenderLineOutput {
|
||||
function _renderLine(input: ResolvedRenderLineInput, sb: StringBuilder): RenderLineOutput {
|
||||
const fontIsMonospace = input.fontIsMonospace;
|
||||
const canUseHalfwidthRightwardsArrow = input.canUseHalfwidthRightwardsArrow;
|
||||
const containsForeignElements = input.containsForeignElements;
|
||||
|
|
|
@ -13,7 +13,7 @@ import { EditorFontLigatures, EditorOption, IComputedEditorOptions } from 'vs/ed
|
|||
import { LineTokens } from 'vs/editor/common/tokens/lineTokens';
|
||||
import { Position } from 'vs/editor/common/core/position';
|
||||
import { Range } from 'vs/editor/common/core/range';
|
||||
import { createStringBuilder } from 'vs/editor/common/core/stringBuilder';
|
||||
import { StringBuilder } from 'vs/editor/common/core/stringBuilder';
|
||||
import { IModelDeltaDecoration, InjectedTextCursorStops, PositionAffinity } from 'vs/editor/common/model';
|
||||
import { ILanguageIdCodec } from 'vs/editor/common/languages';
|
||||
import { ILanguageService } from 'vs/editor/common/languages/language';
|
||||
|
@ -356,7 +356,7 @@ function renderLines(domNode: HTMLElement, tabSize: number, lines: LineData[], o
|
|||
const fontInfo = opts.get(EditorOption.fontInfo);
|
||||
const lineHeight = opts.get(EditorOption.lineHeight);
|
||||
|
||||
const sb = createStringBuilder(10000);
|
||||
const sb = new StringBuilder(10000);
|
||||
sb.appendASCIIString('<div class="suggest-preview-text">');
|
||||
|
||||
for (let i = 0, len = lines.length; i < len; i++) {
|
||||
|
|
|
@ -6,7 +6,7 @@ import { Disposable, DisposableStore, IDisposable, toDisposable } from 'vs/base/
|
|||
import { IActiveCodeEditor, ICodeEditor, IOverlayWidget, IOverlayWidgetPosition } from 'vs/editor/browser/editorBrowser';
|
||||
import * as dom from 'vs/base/browser/dom';
|
||||
import { EditorLayoutInfo, EditorOption, RenderLineNumbersType } from 'vs/editor/common/config/editorOptions';
|
||||
import { createStringBuilder } from 'vs/editor/common/core/stringBuilder';
|
||||
import { StringBuilder } from 'vs/editor/common/core/stringBuilder';
|
||||
import { RenderLineInput, renderViewLine } from 'vs/editor/common/viewLayout/viewLineRenderer';
|
||||
import { LineDecoration } from 'vs/editor/common/viewLayout/lineDecorations';
|
||||
import { Position } from 'vs/editor/common/core/position';
|
||||
|
@ -210,7 +210,7 @@ export class StickyScrollWidget extends Disposable implements IOverlayWidget {
|
|||
lineRenderingData.tabSize, lineRenderingData.startVisibleColumn,
|
||||
1, 1, 1, 500, 'none', true, true, null);
|
||||
|
||||
const sb = createStringBuilder(2000);
|
||||
const sb = new StringBuilder(2000);
|
||||
renderViewLine(renderLineInput, sb);
|
||||
|
||||
let newLine;
|
||||
|
|
|
@ -11,7 +11,7 @@ import { URI } from 'vs/base/common/uri';
|
|||
import { EditOperation } from 'vs/editor/common/core/editOperation';
|
||||
import { Range } from 'vs/editor/common/core/range';
|
||||
import { Selection } from 'vs/editor/common/core/selection';
|
||||
import { createStringBuilder } from 'vs/editor/common/core/stringBuilder';
|
||||
import { StringBuilder } from 'vs/editor/common/core/stringBuilder';
|
||||
import { DefaultEndOfLine, ITextModel } from 'vs/editor/common/model';
|
||||
import { createTextBuffer } from 'vs/editor/common/model/textModel';
|
||||
import { ModelService } from 'vs/editor/common/services/modelService';
|
||||
|
@ -643,7 +643,7 @@ function getRandomInt(min: number, max: number): number {
|
|||
|
||||
function getRandomString(minLength: number, maxLength: number): string {
|
||||
const length = getRandomInt(minLength, maxLength);
|
||||
const t = createStringBuilder(length);
|
||||
const t = new StringBuilder(length);
|
||||
for (let i = 0; i < length; i++) {
|
||||
t.appendASCII(getRandomInt(CharCode.a, CharCode.z));
|
||||
}
|
||||
|
|
|
@ -18,7 +18,7 @@ import { IThemeService } from 'vs/platform/theme/common/themeService';
|
|||
import { EditorPane } from 'vs/workbench/browser/parts/editor/editorPane';
|
||||
import { CONTEXT_LANGUAGE_SUPPORTS_DISASSEMBLE_REQUEST, DISASSEMBLY_VIEW_ID, IDebugService, IDebugSession, IInstructionBreakpoint, State, IDebugConfiguration } from 'vs/workbench/contrib/debug/common/debug';
|
||||
import * as icons from 'vs/workbench/contrib/debug/browser/debugIcons';
|
||||
import { createStringBuilder } from 'vs/editor/common/core/stringBuilder';
|
||||
import { StringBuilder } from 'vs/editor/common/core/stringBuilder';
|
||||
import { IListAccessibilityProvider } from 'vs/base/browser/ui/list/listWidget';
|
||||
import { dispose, Disposable, IDisposable } from 'vs/base/common/lifecycle';
|
||||
import { Emitter } from 'vs/base/common/event';
|
||||
|
@ -618,14 +618,14 @@ class InstructionRenderer extends Disposable implements ITableRenderer<IDisassem
|
|||
templateData.currentElement.element = element;
|
||||
const instruction = element.instruction;
|
||||
templateData.sourcecode.innerText = '';
|
||||
const sb = createStringBuilder(1000);
|
||||
const sb = new StringBuilder(1000);
|
||||
|
||||
if (this._disassemblyView.isSourceCodeRender && instruction.location?.path && instruction.line) {
|
||||
const sourceURI = this.getUriFromSource(instruction);
|
||||
|
||||
if (sourceURI) {
|
||||
let textModel: ITextModel | undefined = undefined;
|
||||
const sourceSB = createStringBuilder(10000);
|
||||
const sourceSB = new StringBuilder(10000);
|
||||
const ref = await this.textModelService.createModelReference(sourceURI);
|
||||
textModel = ref.object.textEditorModel;
|
||||
templateData.cellDisposable.push(ref);
|
||||
|
|
Loading…
Reference in a new issue