debt - Avoid Number.MIN_VALUE and Number.MAX_VALUE

This commit is contained in:
Alex Dima
2019-10-12 00:22:46 +02:00
parent 78fd1e5ec2
commit 1f01e888f2
23 changed files with 65 additions and 60 deletions
+7 -6
View File
@@ -5,6 +5,7 @@
import { DiffChange } from 'vs/base/common/diff/diffChange';
import { stringHash } from 'vs/base/common/hash';
import { Constants } from 'vs/base/common/uint';
export class StringDiffSequence implements ISequence {
@@ -138,8 +139,8 @@ class DiffChangeHelper {
*/
constructor() {
this.m_changes = [];
this.m_originalStart = Number.MAX_VALUE;
this.m_modifiedStart = Number.MAX_VALUE;
this.m_originalStart = Constants.MAX_SAFE_SMALL_INTEGER;
this.m_modifiedStart = Constants.MAX_SAFE_SMALL_INTEGER;
this.m_originalCount = 0;
this.m_modifiedCount = 0;
}
@@ -158,8 +159,8 @@ class DiffChangeHelper {
// Reset for the next change
this.m_originalCount = 0;
this.m_modifiedCount = 0;
this.m_originalStart = Number.MAX_VALUE;
this.m_modifiedStart = Number.MAX_VALUE;
this.m_originalStart = Constants.MAX_SAFE_SMALL_INTEGER;
this.m_modifiedStart = Constants.MAX_SAFE_SMALL_INTEGER;
}
/**
@@ -422,7 +423,7 @@ export class LcsDiff {
let diagonalMin = diagonalForwardStart;
let diagonalMax = diagonalForwardEnd;
let diagonalRelative = (midOriginalArr[0] - midModifiedArr[0]) - diagonalForwardOffset;
let lastOriginalIndex = Number.MIN_VALUE;
let lastOriginalIndex = Constants.MIN_SAFE_SMALL_INTEGER;
let historyIndex = this.m_forwardHistory.length - 1;
let diagonal: number;
@@ -488,7 +489,7 @@ export class LcsDiff {
diagonalMin = diagonalReverseStart;
diagonalMax = diagonalReverseEnd;
diagonalRelative = (midOriginalArr[0] - midModifiedArr[0]) - diagonalReverseOffset;
lastOriginalIndex = Number.MAX_VALUE;
lastOriginalIndex = Constants.MAX_SAFE_SMALL_INTEGER;
historyIndex = (deltaIsEven) ? this.m_reverseHistory.length - 1 : this.m_reverseHistory.length - 2;
do {
@@ -3,32 +3,6 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
export class Uint8Matrix {
private readonly _data: Uint8Array;
public readonly rows: number;
public readonly cols: number;
constructor(rows: number, cols: number, defaultValue: number) {
const data = new Uint8Array(rows * cols);
for (let i = 0, len = rows * cols; i < len; i++) {
data[i] = defaultValue;
}
this._data = data;
this.rows = rows;
this.cols = cols;
}
public get(row: number, col: number): number {
return this._data[row * this.cols + col];
}
public set(row: number, col: number, value: number): void {
this._data[row * this.cols + col] = value;
}
}
export const enum Constants {
/**
* MAX SMI (SMall Integer) as defined in v8.
@@ -9,7 +9,7 @@ import { ContentWidgetPositionPreference, IContentWidget } from 'vs/editor/brows
import { PartFingerprint, PartFingerprints, ViewPart } from 'vs/editor/browser/view/viewPart';
import { IPosition, Position } from 'vs/editor/common/core/position';
import { IRange, Range } from 'vs/editor/common/core/range';
import { Constants } from 'vs/editor/common/core/uint';
import { Constants } from 'vs/base/common/uint';
import { RenderingContext, RestrictedRenderingContext } from 'vs/editor/common/view/renderingContext';
import { ViewContext } from 'vs/editor/common/view/viewContext';
import * as viewEvents from 'vs/editor/common/view/viewEvents';
@@ -3,7 +3,7 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { Constants } from 'vs/editor/common/core/uint';
import { Constants } from 'vs/base/common/uint';
import { HorizontalRange } from 'vs/editor/common/view/renderingContext';
class FloatHorizontalRange {
@@ -20,6 +20,7 @@ import * as viewEvents from 'vs/editor/common/view/viewEvents';
import { ViewportData } from 'vs/editor/common/viewLayout/viewLinesViewportData';
import { Viewport } from 'vs/editor/common/viewModel/viewModel';
import { EditorOption } from 'vs/editor/common/config/editorOptions';
import { Constants } from 'vs/base/common/uint';
class LastRenderedData {
@@ -641,7 +642,7 @@ export class ViewLines extends ViewPart implements IVisibleLinesHost<ViewLine>,
const viewportEndX = viewportStartX + viewport.width;
const visibleRanges = this.visibleRangesForRange2(new Range(lineNumber, startColumn, lineNumber, endColumn));
let boxStartX = Number.MAX_VALUE;
let boxStartX = Constants.MAX_SAFE_SMALL_INTEGER;
let boxEndX = 0;
if (!visibleRanges) {
@@ -43,6 +43,7 @@ import { ITheme, IThemeService, getThemeTypeSelector, registerThemingParticipant
import { IContextMenuService } from 'vs/platform/contextview/browser/contextView';
import { IDiffLinesChange, InlineDiffMargin } from 'vs/editor/browser/widget/inlineDiffMargin';
import { IClipboardService } from 'vs/platform/clipboard/common/clipboardService';
import { Constants } from 'vs/base/common/uint';
interface IEditorDiffDecorations {
decorations: IModelDeltaDecoration[];
@@ -1122,7 +1123,7 @@ export class DiffEditorWidget extends Disposable implements editorBrowser.IDiffE
while (min < max) {
let mid = Math.floor((min + max) / 2);
let midStart = startLineNumberExtractor(lineChanges[mid]);
let midEnd = (mid + 1 <= max ? startLineNumberExtractor(lineChanges[mid + 1]) : Number.MAX_VALUE);
let midEnd = (mid + 1 <= max ? startLineNumberExtractor(lineChanges[mid + 1]) : Constants.MAX_SAFE_SMALL_INTEGER);
if (lineNumber < midStart) {
max = mid - 1;
@@ -1682,11 +1683,11 @@ class DiffEditorWidgetSideBySide extends DiffEditorWidgetStyle implements IDiffE
if (isChangeOrDelete(lineChange)) {
result.decorations.push({
range: new Range(lineChange.originalStartLineNumber, 1, lineChange.originalEndLineNumber, Number.MAX_VALUE),
range: new Range(lineChange.originalStartLineNumber, 1, lineChange.originalEndLineNumber, Constants.MAX_SAFE_SMALL_INTEGER),
options: (renderIndicators ? DECORATIONS.lineDeleteWithSign : DECORATIONS.lineDelete)
});
if (!isChangeOrInsert(lineChange) || !lineChange.charChanges) {
result.decorations.push(createDecoration(lineChange.originalStartLineNumber, 1, lineChange.originalEndLineNumber, Number.MAX_VALUE, DECORATIONS.charDeleteWholeLine));
result.decorations.push(createDecoration(lineChange.originalStartLineNumber, 1, lineChange.originalEndLineNumber, Constants.MAX_SAFE_SMALL_INTEGER, DECORATIONS.charDeleteWholeLine));
}
result.overviewZones.push(new OverviewRulerZone(
@@ -1743,11 +1744,11 @@ class DiffEditorWidgetSideBySide extends DiffEditorWidgetStyle implements IDiffE
if (isChangeOrInsert(lineChange)) {
result.decorations.push({
range: new Range(lineChange.modifiedStartLineNumber, 1, lineChange.modifiedEndLineNumber, Number.MAX_VALUE),
range: new Range(lineChange.modifiedStartLineNumber, 1, lineChange.modifiedEndLineNumber, Constants.MAX_SAFE_SMALL_INTEGER),
options: (renderIndicators ? DECORATIONS.lineInsertWithSign : DECORATIONS.lineInsert)
});
if (!isChangeOrDelete(lineChange) || !lineChange.charChanges) {
result.decorations.push(createDecoration(lineChange.modifiedStartLineNumber, 1, lineChange.modifiedEndLineNumber, Number.MAX_VALUE, DECORATIONS.charInsertWholeLine));
result.decorations.push(createDecoration(lineChange.modifiedStartLineNumber, 1, lineChange.modifiedEndLineNumber, Constants.MAX_SAFE_SMALL_INTEGER, DECORATIONS.charInsertWholeLine));
}
result.overviewZones.push(new OverviewRulerZone(
lineChange.modifiedStartLineNumber,
@@ -1861,7 +1862,7 @@ class DiffEditorWidgetInline extends DiffEditorWidgetStyle implements IDiffEdito
// Add overview zones in the overview ruler
if (isChangeOrDelete(lineChange)) {
result.decorations.push({
range: new Range(lineChange.originalStartLineNumber, 1, lineChange.originalEndLineNumber, Number.MAX_VALUE),
range: new Range(lineChange.originalStartLineNumber, 1, lineChange.originalEndLineNumber, Constants.MAX_SAFE_SMALL_INTEGER),
options: DECORATIONS.lineDeleteMargin
});
@@ -1892,7 +1893,7 @@ class DiffEditorWidgetInline extends DiffEditorWidgetStyle implements IDiffEdito
// Add decorations & overview zones
if (isChangeOrInsert(lineChange)) {
result.decorations.push({
range: new Range(lineChange.modifiedStartLineNumber, 1, lineChange.modifiedEndLineNumber, Number.MAX_VALUE),
range: new Range(lineChange.modifiedStartLineNumber, 1, lineChange.modifiedEndLineNumber, Constants.MAX_SAFE_SMALL_INTEGER),
options: (renderIndicators ? DECORATIONS.lineInsertWithSign : DECORATIONS.lineInsert)
});
@@ -1928,7 +1929,7 @@ class DiffEditorWidgetInline extends DiffEditorWidgetStyle implements IDiffEdito
}
}
} else {
result.decorations.push(createDecoration(lineChange.modifiedStartLineNumber, 1, lineChange.modifiedEndLineNumber, Number.MAX_VALUE, DECORATIONS.charInsertWholeLine));
result.decorations.push(createDecoration(lineChange.modifiedStartLineNumber, 1, lineChange.modifiedEndLineNumber, Constants.MAX_SAFE_SMALL_INTEGER, DECORATIONS.charInsertWholeLine));
}
}
}
+1 -1
View File
@@ -7,7 +7,7 @@ import * as nls from 'vs/nls';
import * as platform from 'vs/base/common/platform';
import { ScrollbarVisibility } from 'vs/base/common/scrollable';
import { FontInfo } from 'vs/editor/common/config/fontInfo';
import { Constants } from 'vs/editor/common/core/uint';
import { Constants } from 'vs/base/common/uint';
import { USUAL_WORD_SEPARATORS } from 'vs/editor/common/model/wordHelper';
import { AccessibilitySupport } from 'vs/platform/accessibility/common/accessibility';
import { isObject } from 'vs/base/common/types';
@@ -3,7 +3,7 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { toUint8 } from 'vs/editor/common/core/uint';
import { toUint8 } from 'vs/base/common/uint';
/**
* A fast character classifier that uses a compact array for ASCII values.
+26 -1
View File
@@ -5,7 +5,6 @@
import { CharCode } from 'vs/base/common/charCode';
import { CharacterClassifier } from 'vs/editor/common/core/characterClassifier';
import { Uint8Matrix } from 'vs/editor/common/core/uint';
import { ILink } from 'vs/editor/common/modes';
export interface ILinkComputerTarget {
@@ -33,6 +32,32 @@ export const enum State {
export type Edge = [State, number, State];
export class Uint8Matrix {
private readonly _data: Uint8Array;
public readonly rows: number;
public readonly cols: number;
constructor(rows: number, cols: number, defaultValue: number) {
const data = new Uint8Array(rows * cols);
for (let i = 0, len = rows * cols; i < len; i++) {
data[i] = defaultValue;
}
this._data = data;
this.rows = rows;
this.cols = cols;
}
public get(row: number, col: number): number {
return this._data[row * this.cols + col];
}
public set(row: number, col: number, value: number): void {
this._data[row * this.cols + col] = value;
}
}
export class StateMachine {
private readonly _states: Uint8Matrix;
@@ -4,7 +4,7 @@
*--------------------------------------------------------------------------------------------*/
import * as strings from 'vs/base/common/strings';
import { Constants } from 'vs/editor/common/core/uint';
import { Constants } from 'vs/base/common/uint';
import { InlineDecoration, InlineDecorationType } from 'vs/editor/common/viewModel/viewModel';
import { equals } from 'vs/base/common/arrays';
@@ -7,7 +7,7 @@ import { CharCode } from 'vs/base/common/charCode';
import * as strings from 'vs/base/common/strings';
import { WrappingIndent } from 'vs/editor/common/config/editorOptions';
import { CharacterClassifier } from 'vs/editor/common/core/characterClassifier';
import { toUint32Array } from 'vs/editor/common/core/uint';
import { toUint32Array } from 'vs/base/common/uint';
import { PrefixSumComputer } from 'vs/editor/common/viewModel/prefixSumComputer';
import { ILineMapperFactory, ILineMapping, OutputPosition } from 'vs/editor/common/viewModel/splitLinesCollection';
@@ -3,7 +3,7 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { toUint32 } from 'vs/editor/common/core/uint';
import { toUint32 } from 'vs/base/common/uint';
export class PrefixSumIndexOfResult {
_prefixSumIndexOfResultBrand: void;
@@ -13,6 +13,7 @@ import * as editorCommon from 'vs/editor/common/editorCommon';
import { IIdentifiedSingleEditOperation, ITextModel } from 'vs/editor/common/model';
import { LanguageConfigurationRegistry } from 'vs/editor/common/modes/languageConfigurationRegistry';
import { BlockCommentCommand } from 'vs/editor/contrib/comment/blockCommentCommand';
import { Constants } from 'vs/base/common/uint';
export interface IInsertionPoint {
ignore: boolean;
@@ -392,7 +393,7 @@ export class LineCommentCommand implements editorCommon.ICommand {
* Adjust insertion points to have them vertically aligned in the add line comment case
*/
public static _normalizeInsertionPoint(model: ISimpleModel, lines: IInsertionPoint[], startLineNumber: number, tabSize: number): void {
let minVisibleColumn = Number.MAX_VALUE;
let minVisibleColumn = Constants.MAX_SAFE_SMALL_INTEGER;
let j: number;
let lenJ: number;
+1 -1
View File
@@ -12,7 +12,7 @@ import { CursorChangeReason, ICursorPositionChangedEvent } from 'vs/editor/commo
import { Position } from 'vs/editor/common/core/position';
import { Range } from 'vs/editor/common/core/range';
import { Selection } from 'vs/editor/common/core/selection';
import { Constants } from 'vs/editor/common/core/uint';
import { Constants } from 'vs/base/common/uint';
import * as editorCommon from 'vs/editor/common/editorCommon';
import { EndOfLinePreference, FindMatch, ITextModel } from 'vs/editor/common/model';
import { SearchParams } from 'vs/editor/common/model/textModelSearch';
@@ -38,6 +38,7 @@ import { CodeActionKind } from 'vs/editor/contrib/codeAction/codeActionTrigger';
import { IModeService } from 'vs/editor/common/services/modeService';
import { IIdentifiedSingleEditOperation } from 'vs/editor/common/model';
import { EditorOption } from 'vs/editor/common/config/editorOptions';
import { Constants } from 'vs/base/common/uint';
const $ = dom.$;
@@ -333,7 +334,7 @@ export class ModesContentHoverWidget extends ContentHoverWidget {
this._colorPicker = null;
// update column from which to show
let renderColumn = Number.MAX_VALUE;
let renderColumn = Constants.MAX_SAFE_SMALL_INTEGER;
let highlightRange: Range | null = messages[0].range ? Range.lift(messages[0].range) : null;
let fragment = document.createDocumentFragment();
let isEmptyHoverContent = true;
@@ -14,7 +14,7 @@ import { CursorChangeReason, ICursorSelectionChangedEvent } from 'vs/editor/comm
import { CursorMoveCommands } from 'vs/editor/common/controller/cursorMoveCommands';
import { Range } from 'vs/editor/common/core/range';
import { Selection } from 'vs/editor/common/core/selection';
import { Constants } from 'vs/editor/common/core/uint';
import { Constants } from 'vs/base/common/uint';
import { IEditorContribution, ScrollType } from 'vs/editor/common/editorCommon';
import { EditorContextKeys } from 'vs/editor/common/editorContextKeys';
import { FindMatch, ITextModel, OverviewRulerLane, TrackedRangeStickiness } from 'vs/editor/common/model';
@@ -15,6 +15,7 @@ import { Location, LocationLink } from 'vs/editor/common/modes';
import { ITextModelService, ITextEditorModel } from 'vs/editor/common/services/resolverService';
import { Position } from 'vs/editor/common/core/position';
import { IMatch } from 'vs/base/common/filters';
import { Constants } from 'vs/base/common/uint';
export class OneReference {
readonly id: string;
@@ -72,7 +73,7 @@ export class FilePreview implements IDisposable {
const { startLineNumber, startColumn, endLineNumber, endColumn } = range;
const word = model.getWordUntilPosition({ lineNumber: startLineNumber, column: startColumn - n });
const beforeRange = new Range(startLineNumber, word.startColumn, startLineNumber, startColumn);
const afterRange = new Range(endLineNumber, endColumn, endLineNumber, Number.MAX_VALUE);
const afterRange = new Range(endLineNumber, endColumn, endLineNumber, Constants.MAX_SAFE_SMALL_INTEGER);
const before = model.getValueInRange(beforeRange).replace(/^\s+/, '');
const inside = model.getValueInRange(range);
@@ -4,7 +4,7 @@
*--------------------------------------------------------------------------------------------*/
import * as assert from 'assert';
import { toUint32Array } from 'vs/editor/common/core/uint';
import { toUint32Array } from 'vs/base/common/uint';
import { PrefixSumComputer, PrefixSumIndexOfResult } from 'vs/editor/common/viewModel/prefixSumComputer';
suite('Editor ViewModel - PrefixSumComputer', () => {
@@ -9,7 +9,7 @@ import { IViewLineTokens } from 'vs/editor/common/core/lineTokens';
import { Position } from 'vs/editor/common/core/position';
import { IRange, Range } from 'vs/editor/common/core/range';
import { TokenizationResult2 } from 'vs/editor/common/core/token';
import { toUint32Array } from 'vs/editor/common/core/uint';
import { toUint32Array } from 'vs/base/common/uint';
import { EndOfLinePreference } from 'vs/editor/common/model';
import { TextModel } from 'vs/editor/common/model/textModel';
import * as modes from 'vs/editor/common/modes';
@@ -14,7 +14,7 @@ import { IContextMenuService, IContextViewService } from 'vs/platform/contextvie
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
import { IKeybindingService } from 'vs/platform/keybinding/common/keybinding';
import { IThemeService } from 'vs/platform/theme/common/themeService';
import { Constants } from 'vs/editor/common/core/uint';
import { Constants } from 'vs/base/common/uint';
import { dispose, IDisposable } from 'vs/base/common/lifecycle';
import { Separator } from 'vs/base/browser/ui/actionbar/actionbar';
import { IListVirtualDelegate, IListContextMenuEvent, IListRenderer } from 'vs/base/browser/ui/list/list';
@@ -3,7 +3,7 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { Constants } from 'vs/editor/common/core/uint';
import { Constants } from 'vs/base/common/uint';
import { Range } from 'vs/editor/common/core/range';
import { ITextModel, TrackedRangeStickiness, IModelDeltaDecoration, IModelDecorationOptions } from 'vs/editor/common/model';
import { IWorkbenchContribution } from 'vs/workbench/common/contributions';
@@ -7,7 +7,7 @@ import * as nls from 'vs/nls';
import { RunOnceScheduler } from 'vs/base/common/async';
import * as env from 'vs/base/common/platform';
import { visit } from 'vs/base/common/json';
import { Constants } from 'vs/editor/common/core/uint';
import { Constants } from 'vs/base/common/uint';
import { KeyCode } from 'vs/base/common/keyCodes';
import { IKeyboardEvent } from 'vs/base/browser/keyboardEvent';
import { StandardTokenType } from 'vs/editor/common/modes';
@@ -39,7 +39,7 @@ import { Schemas } from 'vs/base/common/network';
import { IDialogService, IConfirmationResult, getConfirmMessage } from 'vs/platform/dialogs/common/dialogs';
import { INotificationService, Severity } from 'vs/platform/notification/common/notification';
import { IEditorService } from 'vs/workbench/services/editor/common/editorService';
import { Constants } from 'vs/editor/common/core/uint';
import { Constants } from 'vs/base/common/uint';
import { CLOSE_EDITORS_AND_GROUP_COMMAND_ID } from 'vs/workbench/browser/parts/editor/editorCommands';
import { coalesce } from 'vs/base/common/arrays';
import { AsyncDataTree } from 'vs/base/browser/ui/tree/asyncDataTree';