From 2b5f4eb9fe7b4ce862b9cd6a31671baf3e86a093 Mon Sep 17 00:00:00 2001 From: yann300 Date: Mon, 21 Nov 2022 19:36:44 +0100 Subject: [PATCH] adding cache --- .../src/lib/offset-line-to-column-converter.ts | 13 ++++++++++++- .../src/source/offsetToLineColumnConverter.ts | 12 +++++++++++- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/libs/remix-core-plugin/src/lib/offset-line-to-column-converter.ts b/libs/remix-core-plugin/src/lib/offset-line-to-column-converter.ts index b6e02bbcdd..0c416b2953 100644 --- a/libs/remix-core-plugin/src/lib/offset-line-to-column-converter.ts +++ b/libs/remix-core-plugin/src/lib/offset-line-to-column-converter.ts @@ -13,9 +13,11 @@ const profile = { export class OffsetToLineColumnConverter extends Plugin { lineBreakPositionsByContent: Record> sourceMappingDecoder: any + offsetConvertion: any constructor () { super(profile) this.lineBreakPositionsByContent = {} + this.offsetConvertion = {} this.sourceMappingDecoder = sourceMappingDecoder } @@ -45,7 +47,15 @@ export class OffsetToLineColumnConverter extends Plugin { } } } - return this.sourceMappingDecoder.convertOffsetToLineColumn(rawLocation, this.lineBreakPositionsByContent[file]) + + const token = `${rawLocation.start}:${rawLocation.length}:${file}` + if (this.offsetConvertion[token]) { + return this.offsetConvertion[token] + } else { + const convertion = this.sourceMappingDecoder.convertOffsetToLineColumn(rawLocation, this.lineBreakPositionsByContent[file]) + this.offsetConvertion[token] = convertion + return convertion + } } /** @@ -64,6 +74,7 @@ export class OffsetToLineColumnConverter extends Plugin { */ clear () { this.lineBreakPositionsByContent = {} + this.offsetConvertion = {} } /** diff --git a/libs/remix-debug/src/source/offsetToLineColumnConverter.ts b/libs/remix-debug/src/source/offsetToLineColumnConverter.ts index 6605b660b9..a1f296c76f 100644 --- a/libs/remix-debug/src/source/offsetToLineColumnConverter.ts +++ b/libs/remix-debug/src/source/offsetToLineColumnConverter.ts @@ -4,9 +4,11 @@ import { getLinebreakPositions, convertOffsetToLineColumn } from './sourceMappin export class OffsetToColumnConverter { lineBreakPositionsByContent sourceMappingDecoder + offsetConvertion constructor (compilerEvent) { this.lineBreakPositionsByContent = {} + this.offsetConvertion = {} if (compilerEvent) { compilerEvent.register('compilationFinished', (success, data, source, input, version) => { this.clear() @@ -26,10 +28,18 @@ export class OffsetToColumnConverter { } } } - return convertOffsetToLineColumn(rawLocation, this.lineBreakPositionsByContent[file]) + const token = `${rawLocation.start}:${rawLocation.length}:${file}` + if (this.offsetConvertion[token]) { + return this.offsetConvertion[token] + } else { + const convertion = convertOffsetToLineColumn(rawLocation, this.lineBreakPositionsByContent[file]) + this.offsetConvertion[token] = convertion + return convertion + } } clear () { this.lineBreakPositionsByContent = {} + this.offsetConvertion = {} } }