From 3fe45ba47d3975749732d51e8941881547b6d4b9 Mon Sep 17 00:00:00 2001 From: Alexandru Dima Date: Fri, 18 Oct 2019 15:48:44 +0200 Subject: [PATCH] Partial Revert "Use equals helper function instead of re-implementing it so many places" This reverts commit 40e0f496f97bd655f114d25084dc4a7b88b81299. --- src/vs/base/common/keyCodes.ts | 11 ++++++++-- src/vs/editor/common/core/selection.ts | 11 ++++++++-- .../common/viewLayout/lineDecorations.ts | 15 ++++++++++--- .../common/viewLayout/viewLineRenderer.ts | 13 ++++++++++-- .../editor/contrib/cursorUndo/cursorUndo.ts | 13 ++++++++++-- .../editor/test/common/core/viewLineToken.ts | 15 ++++++++++--- .../platform/contextkey/common/contextkey.ts | 21 ++++++++++++++++--- 7 files changed, 82 insertions(+), 17 deletions(-) diff --git a/src/vs/base/common/keyCodes.ts b/src/vs/base/common/keyCodes.ts index 98ac19e0843..ec08bea7e91 100644 --- a/src/vs/base/common/keyCodes.ts +++ b/src/vs/base/common/keyCodes.ts @@ -5,7 +5,6 @@ import { OperatingSystem } from 'vs/base/common/platform'; import { illegalArgument } from 'vs/base/common/errors'; -import { equals } from 'vs/base/common/arrays'; /** * Virtual Key Codes, the value does not hold any inherent meaning. @@ -526,7 +525,15 @@ export class ChordKeybinding { if (other === null) { return false; } - return equals(this.parts, other.parts, (a, b) => a.equals(b)); + if (this.parts.length !== other.parts.length) { + return false; + } + for (let i = 0; i < this.parts.length; i++) { + if (!this.parts[i].equals(other.parts[i])) { + return false; + } + } + return true; } } diff --git a/src/vs/editor/common/core/selection.ts b/src/vs/editor/common/core/selection.ts index b1776654e94..80143cdf97a 100644 --- a/src/vs/editor/common/core/selection.ts +++ b/src/vs/editor/common/core/selection.ts @@ -5,7 +5,6 @@ import { IPosition, Position } from 'vs/editor/common/core/position'; import { Range } from 'vs/editor/common/core/range'; -import { equals } from 'vs/base/common/arrays'; /** * A selection in the editor. @@ -172,7 +171,15 @@ export class Selection extends Range { if (!a && !b) { return true; } - return equals(a, b, this.selectionsEqual); + if (a.length !== b.length) { + return false; + } + for (let i = 0, len = a.length; i < len; i++) { + if (!this.selectionsEqual(a[i], b[i])) { + return false; + } + } + return true; } /** diff --git a/src/vs/editor/common/viewLayout/lineDecorations.ts b/src/vs/editor/common/viewLayout/lineDecorations.ts index a384c18a977..367abd68f82 100644 --- a/src/vs/editor/common/viewLayout/lineDecorations.ts +++ b/src/vs/editor/common/viewLayout/lineDecorations.ts @@ -6,7 +6,6 @@ import * as strings from 'vs/base/common/strings'; import { Constants } from 'vs/base/common/uint'; import { InlineDecoration, InlineDecorationType } from 'vs/editor/common/viewModel/viewModel'; -import { equals } from 'vs/base/common/arrays'; export class LineDecoration { _lineDecorationBrand: void; @@ -28,8 +27,18 @@ export class LineDecoration { ); } - public static equalsArr(a: readonly LineDecoration[], b: readonly LineDecoration[]): boolean { - return equals(a, b, LineDecoration._equals); + public static equalsArr(a: LineDecoration[], b: LineDecoration[]): boolean { + let aLen = a.length; + let bLen = b.length; + if (aLen !== bLen) { + return false; + } + for (let i = 0; i < aLen; i++) { + if (!LineDecoration._equals(a[i], b[i])) { + return false; + } + } + return true; } public static filter(lineDecorations: InlineDecoration[], lineNumber: number, minLineColumn: number, maxLineColumn: number): LineDecoration[] { diff --git a/src/vs/editor/common/viewLayout/viewLineRenderer.ts b/src/vs/editor/common/viewLayout/viewLineRenderer.ts index 0b41b006f65..bbb9b39cb8c 100644 --- a/src/vs/editor/common/viewLayout/viewLineRenderer.ts +++ b/src/vs/editor/common/viewLayout/viewLineRenderer.ts @@ -9,7 +9,6 @@ import { IViewLineTokens } from 'vs/editor/common/core/lineTokens'; import { IStringBuilder, createStringBuilder } from 'vs/editor/common/core/stringBuilder'; import { LineDecoration, LineDecorationsNormalizer } from 'vs/editor/common/viewLayout/lineDecorations'; import { InlineDecorationType } from 'vs/editor/common/viewModel/viewModel'; -import { equals } from 'vs/base/common/arrays'; export const enum RenderWhitespace { None = 0, @@ -132,7 +131,17 @@ export class RenderLineInput { return false; } - return equals(this.selectionsOnLine, otherSelections, (a, b) => a.equals(b)); + if (otherSelections.length !== this.selectionsOnLine.length) { + return false; + } + + for (let i = 0; i < this.selectionsOnLine.length; i++) { + if (!this.selectionsOnLine[i].equals(otherSelections[i])) { + return false; + } + } + + return true; } public equals(other: RenderLineInput): boolean { diff --git a/src/vs/editor/contrib/cursorUndo/cursorUndo.ts b/src/vs/editor/contrib/cursorUndo/cursorUndo.ts index 5a77a0a1dd6..f23fa5dfe0d 100644 --- a/src/vs/editor/contrib/cursorUndo/cursorUndo.ts +++ b/src/vs/editor/contrib/cursorUndo/cursorUndo.ts @@ -12,7 +12,6 @@ import { Selection } from 'vs/editor/common/core/selection'; import { IEditorContribution, ScrollType } from 'vs/editor/common/editorCommon'; import { EditorContextKeys } from 'vs/editor/common/editorContextKeys'; import { KeybindingWeight } from 'vs/platform/keybinding/common/keybindingsRegistry'; -import { equals } from 'vs/base/common/arrays'; class CursorState { readonly selections: readonly Selection[]; @@ -22,7 +21,17 @@ class CursorState { } public equals(other: CursorState): boolean { - return equals(this.selections, other.selections, (a, b) => a.equalsSelection(b)); + const thisLen = this.selections.length; + const otherLen = other.selections.length; + if (thisLen !== otherLen) { + return false; + } + for (let i = 0; i < thisLen; i++) { + if (!this.selections[i].equalsSelection(other.selections[i])) { + return false; + } + } + return true; } } diff --git a/src/vs/editor/test/common/core/viewLineToken.ts b/src/vs/editor/test/common/core/viewLineToken.ts index d91fe77bcf0..340157110ae 100644 --- a/src/vs/editor/test/common/core/viewLineToken.ts +++ b/src/vs/editor/test/common/core/viewLineToken.ts @@ -5,7 +5,6 @@ import { IViewLineTokens } from 'vs/editor/common/core/lineTokens'; import { ColorId, TokenMetadata } from 'vs/editor/common/modes'; -import { equals } from 'vs/base/common/arrays'; /** * A token on a line. @@ -43,8 +42,18 @@ export class ViewLineToken { ); } - public static equalsArr(a: readonly ViewLineToken[], b: readonly ViewLineToken[]): boolean { - return equals(a, b, this._equals); + public static equalsArr(a: ViewLineToken[], b: ViewLineToken[]): boolean { + const aLen = a.length; + const bLen = b.length; + if (aLen !== bLen) { + return false; + } + for (let i = 0; i < aLen; i++) { + if (!this._equals(a[i], b[i])) { + return false; + } + } + return true; } } diff --git a/src/vs/platform/contextkey/common/contextkey.ts b/src/vs/platform/contextkey/common/contextkey.ts index ed418e1d89f..16e79df476f 100644 --- a/src/vs/platform/contextkey/common/contextkey.ts +++ b/src/vs/platform/contextkey/common/contextkey.ts @@ -6,7 +6,6 @@ import { Event } from 'vs/base/common/event'; import { isFalsyOrWhitespace } from 'vs/base/common/strings'; import { createDecorator } from 'vs/platform/instantiation/common/instantiation'; -import { equals } from 'vs/base/common/arrays'; export const enum ContextKeyExprType { Defined = 1, @@ -575,7 +574,15 @@ export class ContextKeyAndExpr implements ContextKeyExpr { public equals(other: ContextKeyExpr): boolean { if (other instanceof ContextKeyAndExpr) { - return equals(this.expr, other.expr, (a, b) => a.equals(b)); + if (this.expr.length !== other.expr.length) { + return false; + } + for (let i = 0, len = this.expr.length; i < len; i++) { + if (!this.expr[i].equals(other.expr[i])) { + return false; + } + } + return true; } return false; } @@ -667,7 +674,15 @@ export class ContextKeyOrExpr implements ContextKeyExpr { public equals(other: ContextKeyExpr): boolean { if (other instanceof ContextKeyOrExpr) { - return equals(this.expr, other.expr, (a, b) => a.equals(b)); + if (this.expr.length !== other.expr.length) { + return false; + } + for (let i = 0, len = this.expr.length; i < len; i++) { + if (!this.expr[i].equals(other.expr[i])) { + return false; + } + } + return true; } return false; } -- GitLab