Browse Source

Avoids MAX_SAFE_INTEGER to ensure ints stay smis

In V8 ints less than 2^30 (on 32bit systems) have optimized storage
main
Eric Amodio 2 years ago
parent
commit
48e0595207
12 changed files with 40 additions and 26 deletions
  1. +3
    -1
      src/annotations/blameAnnotationProvider.ts
  2. +3
    -1
      src/annotations/gutterBlameAnnotationProvider.ts
  3. +4
    -2
      src/annotations/gutterChangesAnnotationProvider.ts
  4. +2
    -3
      src/annotations/lineAnnotationController.ts
  5. +3
    -1
      src/api/actionRunners.ts
  6. +3
    -1
      src/avatars.ts
  7. +4
    -2
      src/hovers/lineHoverController.ts
  8. +2
    -1
      src/system/decorators/log.ts
  9. +3
    -1
      src/webviews/apps/shared/appBase.ts
  10. +7
    -11
      src/webviews/rebase/rebaseEditor.ts
  11. +3
    -1
      src/webviews/webviewBase.ts
  12. +3
    -1
      src/webviews/webviewViewBase.ts

+ 3
- 1
src/annotations/blameAnnotationProvider.ts View File

@ -9,6 +9,8 @@ import { GitDocumentState, TrackedDocument } from '../trackers/gitDocumentTracke
import { AnnotationProviderBase } from './annotationProvider';
import { ComputedHeatmap, getHeatmapColors } from './annotations';
const maxSmallIntegerV8 = 2 ** 30; // Max number that can be stored in V8's smis (small integers)
export abstract class BlameAnnotationProviderBase extends AnnotationProviderBase {
protected blame: Promise<GitBlame | undefined>;
protected hoverProviderDisposable: Disposable | undefined;
@ -165,7 +167,7 @@ export abstract class BlameAnnotationProviderBase extends AnnotationProviderBase
return new Hover(
messages,
document.validateRange(new Range(position.line, 0, position.line, Number.MAX_SAFE_INTEGER)),
document.validateRange(new Range(position.line, 0, position.line, maxSmallIntegerV8)),
);
}

+ 3
- 1
src/annotations/gutterBlameAnnotationProvider.ts View File

@ -17,6 +17,8 @@ import { Annotations } from './annotations';
import { BlameAnnotationProviderBase } from './blameAnnotationProvider';
import { Decorations } from './fileAnnotationController';
const maxSmallIntegerV8 = 2 ** 30; // Max number that can be stored in V8's smis (small integers)
export class GutterBlameAnnotationProvider extends BlameAnnotationProviderBase {
constructor(editor: TextEditor, trackedDocument: TrackedDocument<GitDocumentState>, container: Container) {
super(FileAnnotationType.Blame, editor, trackedDocument, container);
@ -202,7 +204,7 @@ export class GutterBlameAnnotationProvider extends BlameAnnotationProviderBase {
const highlightDecorationRanges = filterMap(blame.lines, l =>
l.sha === sha
? // editor lines are 0-based
this.editor.document.validateRange(new Range(l.line - 1, 0, l.line - 1, Number.MAX_SAFE_INTEGER))
this.editor.document.validateRange(new Range(l.line - 1, 0, l.line - 1, maxSmallIntegerV8))
: undefined,
);

+ 4
- 2
src/annotations/gutterChangesAnnotationProvider.ts View File

@ -23,6 +23,8 @@ import { GitDocumentState, TrackedDocument } from '../trackers/gitDocumentTracke
import { AnnotationContext, AnnotationProviderBase } from './annotationProvider';
import { Decorations } from './fileAnnotationController';
const maxSmallIntegerV8 = 2 ** 30; // Max number that can be stored in V8's smis (small integers)
export interface ChangesAnnotationContext extends AnnotationContext {
sha?: string;
only?: boolean;
@ -204,7 +206,7 @@ export class GutterChangesAnnotationProvider extends AnnotationProviderBase
// }
const range = this.editor.document.validateRange(
new Range(new Position(count, 0), new Position(count, Number.MAX_SAFE_INTEGER)),
new Range(new Position(count, 0), new Position(count, maxSmallIntegerV8)),
);
if (selection == null) {
selection = new Selection(range.start, range.end);
@ -323,7 +325,7 @@ export class GutterChangesAnnotationProvider extends AnnotationProviderBase
hunk.current.position.start - 1,
0,
hunk.current.position.end - (hasMoreDeletedLines ? 0 : 1),
Number.MAX_SAFE_INTEGER,
maxSmallIntegerV8,
),
),
);

+ 2
- 3
src/annotations/lineAnnotationController.ts View File

@ -32,6 +32,7 @@ const annotationDecoration: TextEditorDecorationType = window.createTextEditorDe
},
rangeBehavior: DecorationRangeBehavior.ClosedOpen,
});
const maxSmallIntegerV8 = 2 ** 30; // Max number that can be stored in V8's smis (small integers)
export class LineAnnotationController implements Disposable {
private _cancellation: CancellationTokenSource | undefined;
@ -309,9 +310,7 @@ export class LineAnnotationController implements Disposable {
},
cfg.scrollable,
) as DecorationOptions;
decoration.range = editor.document.validateRange(
new Range(l, Number.MAX_SAFE_INTEGER, l, Number.MAX_SAFE_INTEGER),
);
decoration.range = editor.document.validateRange(new Range(l, maxSmallIntegerV8, l, maxSmallIntegerV8));
decorations.push(decoration);
}

+ 3
- 1
src/api/actionRunners.ts View File

@ -7,6 +7,8 @@ import { sortCompare } from '../system/string';
import { getQuickPickIgnoreFocusOut } from '../system/utils';
import type { Action, ActionContext, ActionRunner } from './gitlens';
const maxSmallIntegerV8 = 2 ** 30; // Max number that can be stored in V8's smis (small integers)
type Actions = ActionContext['type'];
const actions: Actions[] = ['createPullRequest', 'openPullRequest', 'hover.commands'];
@ -50,7 +52,7 @@ class NoActionRunnersQuickPickItem implements QuickPickItem {
let runnerId = 0;
function nextRunnerId() {
if (runnerId === Number.MAX_SAFE_INTEGER) {
if (runnerId === maxSmallIntegerV8) {
runnerId = 1;
} else {
runnerId++;

+ 3
- 1
src/avatars.ts View File

@ -8,6 +8,8 @@ import { filterMap } from './system/iterable';
import { base64, equalsIgnoreCase, md5 } from './system/string';
import { ContactPresenceStatus } from './vsls/vsls';
const maxSmallIntegerV8 = 2 ** 30; // Max number that can be stored in V8's smis (small integers)
const _onDidFetchAvatar = new EventEmitter<{ email: string }>();
_onDidFetchAvatar.event(
debounce(() => {
@ -195,7 +197,7 @@ async function getAvatarUriFromRemoteProvider(
if (account == null) {
// If we have no account assume that won't change (without a reset), so set the timestamp to "never expire"
avatar.uri = undefined;
avatar.timestamp = Number.MAX_SAFE_INTEGER;
avatar.timestamp = maxSmallIntegerV8;
avatar.retries = 0;
return undefined;

+ 4
- 2
src/hovers/lineHoverController.ts View File

@ -20,6 +20,8 @@ import { once } from '../system/event';
import { LinesChangeEvent } from '../trackers/gitLineTracker';
import { Hovers } from './hovers';
const maxSmallIntegerV8 = 2 ** 30; // Max number that can be stored in V8's smis (small integers)
export class LineHoverController implements Disposable {
private readonly _disposable: Disposable;
private _hoverProviderDisposable: Disposable | undefined;
@ -112,7 +114,7 @@ export class LineHoverController implements Disposable {
if (!wholeLine && this.container.lineAnnotations.suspended) return undefined;
const range = document.validateRange(
new Range(position.line, wholeLine ? 0 : Number.MAX_SAFE_INTEGER, position.line, Number.MAX_SAFE_INTEGER),
new Range(position.line, wholeLine ? 0 : maxSmallIntegerV8, position.line, maxSmallIntegerV8),
);
if (!wholeLine && range.start.character !== position.character) return undefined;
@ -169,7 +171,7 @@ export class LineHoverController implements Disposable {
if (!wholeLine && this.container.lineAnnotations.suspended) return undefined;
const range = document.validateRange(
new Range(position.line, wholeLine ? 0 : Number.MAX_SAFE_INTEGER, position.line, Number.MAX_SAFE_INTEGER),
new Range(position.line, wholeLine ? 0 : maxSmallIntegerV8, position.line, maxSmallIntegerV8),
);
if (!wholeLine && range.start.character !== position.character) return undefined;

+ 2
- 1
src/system/decorators/log.ts View File

@ -6,6 +6,7 @@ import { isPromise } from '../promise';
import { getDurationMilliseconds } from '../string';
const emptyStr = '';
const maxSmallIntegerV8 = 2 ** 30; // Max number that can be stored in V8's smis (small integers)
const correlationContext = new Map<number, LogCorrelationContext>();
let correlationCounter = 0;
@ -19,7 +20,7 @@ export function getCorrelationId() {
}
export function getNextCorrelationId() {
if (correlationCounter === Number.MAX_SAFE_INTEGER) {
if (correlationCounter === maxSmallIntegerV8) {
correlationCounter = 0;
}
return ++correlationCounter;

+ 3
- 1
src/webviews/apps/shared/appBase.ts View File

@ -19,9 +19,11 @@ interface VsCodeApi {
declare function acquireVsCodeApi(): VsCodeApi;
const maxSmallIntegerV8 = 2 ** 30; // Max number that can be stored in V8's smis (small integers)
let ipcSequence = 0;
function nextIpcId() {
if (ipcSequence === Number.MAX_SAFE_INTEGER) {
if (ipcSequence === maxSmallIntegerV8) {
ipcSequence = 1;
} else {
ipcSequence++;

+ 7
- 11
src/webviews/rebase/rebaseEditor.ts View File

@ -41,9 +41,11 @@ import {
SwitchCommandType,
} from './protocol';
const maxSmallIntegerV8 = 2 ** 30; // Max number that can be stored in V8's smis (small integers)
let ipcSequence = 0;
function nextIpcId() {
if (ipcSequence === Number.MAX_SAFE_INTEGER) {
if (ipcSequence === maxSmallIntegerV8) {
ipcSequence = 1;
} else {
ipcSequence++;
@ -54,7 +56,7 @@ function nextIpcId() {
let webviewId = 0;
function nextWebviewId() {
if (webviewId === Number.MAX_SAFE_INTEGER) {
if (webviewId === maxSmallIntegerV8) {
webviewId = 1;
} else {
webviewId++;
@ -295,7 +297,7 @@ export class RebaseEditorProvider implements CustomTextEditorProvider, Disposabl
const start = context.document.positionAt(entry.index);
const range = context.document.validateRange(
new Range(new Position(start.line, 0), new Position(start.line, Number.MAX_SAFE_INTEGER)),
new Range(new Position(start.line, 0), new Position(start.line, maxSmallIntegerV8)),
);
let action = params.action;
@ -328,10 +330,7 @@ export class RebaseEditorProvider implements CustomTextEditorProvider, Disposabl
} else {
const start = context.document.positionAt(lastEntry.index);
const range = context.document.validateRange(
new Range(
new Position(start.line, 0),
new Position(start.line, Number.MAX_SAFE_INTEGER),
),
new Range(new Position(start.line, 0), new Position(start.line, maxSmallIntegerV8)),
);
edit.replace(context.document.uri, range, `pick ${lastEntry.ref} ${lastEntry.message}`);
@ -406,10 +405,7 @@ export class RebaseEditorProvider implements CustomTextEditorProvider, Disposabl
} else {
const start = context.document.positionAt(lastEntry.index);
const range = context.document.validateRange(
new Range(
new Position(start.line, 0),
new Position(start.line, Number.MAX_SAFE_INTEGER),
),
new Range(new Position(start.line, 0), new Position(start.line, maxSmallIntegerV8)),
);
edit.replace(context.document.uri, range, `pick ${lastEntry.ref} ${lastEntry.message}`);

+ 3
- 1
src/webviews/webviewBase.ts View File

@ -23,9 +23,11 @@ import {
WebviewReadyCommandType,
} from './protocol';
const maxSmallIntegerV8 = 2 ** 30; // Max number that can be stored in V8's smis (small integers)
let ipcSequence = 0;
function nextIpcId() {
if (ipcSequence === Number.MAX_SAFE_INTEGER) {
if (ipcSequence === maxSmallIntegerV8) {
ipcSequence = 1;
} else {
ipcSequence++;

+ 3
- 1
src/webviews/webviewViewBase.ts View File

@ -25,9 +25,11 @@ import {
WebviewReadyCommandType,
} from './protocol';
const maxSmallIntegerV8 = 2 ** 30; // Max number that can be stored in V8's smis (small integers)
let ipcSequence = 0;
function nextIpcId() {
if (ipcSequence === Number.MAX_SAFE_INTEGER) {
if (ipcSequence === maxSmallIntegerV8) {
ipcSequence = 1;
} else {
ipcSequence++;

Loading…
Cancel
Save