3
3
* Licensed under the MIT License. See License.txt in the project root for license information.
4
4
*--------------------------------------------------------------------------------------------*/
5
5
import { IDiffResult , ISequence , LcsDiff } from '../../../../../base/common/diff/diff.js' ;
6
- import { doHash , numberHash } from '../../../../../base/common/hash.js' ;
6
+ import { doHash , hash , numberHash } from '../../../../../base/common/hash.js' ;
7
7
import { IDisposable } from '../../../../../base/common/lifecycle.js' ;
8
8
import { URI } from '../../../../../base/common/uri.js' ;
9
9
import { IRequestHandler , IWorkerServer } from '../../../../../base/common/worker/simpleWorker.js' ;
@@ -18,7 +18,7 @@ import { filter } from '../../../../../base/common/objects.js';
18
18
19
19
class MirrorCell {
20
20
private readonly textModel : MirrorModel ;
21
- private _hash ?: Promise < number > ;
21
+ private _hash ?: number ;
22
22
public get eol ( ) {
23
23
return this . _eol === '\r\n' ? DefaultEndOfLine . CRLF : DefaultEndOfLine . LF ;
24
24
}
@@ -46,11 +46,11 @@ class MirrorCell {
46
46
return this . textModel . getValue ( ) ;
47
47
}
48
48
49
- async getComparisonValue ( ) : Promise < number > {
49
+ getComparisonValue ( ) : number {
50
50
return this . _hash ??= this . _getHash ( ) ;
51
51
}
52
52
53
- private async _getHash ( ) {
53
+ private _getHash ( ) {
54
54
let hashValue = numberHash ( 104579 , 0 ) ;
55
55
56
56
hashValue = doHash ( this . language , hashValue ) ;
@@ -65,15 +65,13 @@ class MirrorCell {
65
65
}
66
66
}
67
67
68
- // note: hash has not updated within the Promise.all since we must retain order
69
- const digests = await Promise . all ( this . outputs . flatMap ( op =>
70
- op . outputs . map ( o => crypto . subtle . digest ( 'sha-1' , o . data . buffer ) )
71
- ) ) ;
68
+ const digests = this . outputs . flatMap ( op =>
69
+ op . outputs . map ( o => hash ( Array . from ( o . data . buffer ) ) )
70
+ ) ;
72
71
for ( const digest of digests ) {
73
- hashValue = numberHash ( new Int32Array ( digest ) [ 0 ] , hashValue ) ;
72
+ hashValue = numberHash ( digest , hashValue ) ;
74
73
}
75
74
76
-
77
75
return hashValue ;
78
76
}
79
77
}
@@ -148,21 +146,21 @@ class MirrorNotebookDocument {
148
146
149
147
class CellSequence implements ISequence {
150
148
151
- static async create ( textModel : MirrorNotebookDocument ) {
149
+ static create ( textModel : MirrorNotebookDocument ) {
152
150
const hashValue = new Int32Array ( textModel . cells . length ) ;
153
- await Promise . all ( textModel . cells . map ( async ( c , i ) => {
154
- hashValue [ i ] = await c . getComparisonValue ( ) ;
155
- } ) ) ;
151
+ textModel . cells . map ( ( c , i ) => {
152
+ hashValue [ i ] = c . getComparisonValue ( ) ;
153
+ } ) ;
156
154
return new CellSequence ( hashValue ) ;
157
155
}
158
156
159
- static async createWithCellId ( textModel : MirrorNotebookDocument ) : Promise < Map < string , number > > {
157
+ static createWithCellId ( textModel : MirrorNotebookDocument ) : Map < string , number > {
160
158
const hashValue = new Map < string , number > ( ) ;
161
- await Promise . all ( textModel . cells . map ( async ( c , i ) => {
162
- const value = await c . getComparisonValue ( ) ;
159
+ textModel . cells . map ( ( c , i ) => {
160
+ const value = c . getComparisonValue ( ) ;
163
161
const id : string = ( c . metadata ?. id || '' ) as string ;
164
162
hashValue . set ( id , value ) ;
165
- } ) ) ;
163
+ } ) ;
166
164
return hashValue ;
167
165
}
168
166
@@ -220,10 +218,8 @@ export class NotebookEditorSimpleWorker implements IRequestHandler, IDisposable
220
218
const original = this . _getModel ( originalUrl ) ;
221
219
const modified = this . _getModel ( modifiedUrl ) ;
222
220
223
- const [ originalSeq , modifiedSeq ] = await Promise . all ( [
224
- CellSequence . create ( original ) ,
225
- CellSequence . create ( modified ) ,
226
- ] ) ;
221
+ const originalSeq = CellSequence . create ( original ) ;
222
+ const modifiedSeq = CellSequence . create ( modified ) ;
227
223
228
224
const diff = new LcsDiff ( originalSeq , modifiedSeq ) ;
229
225
const diffResult = diff . ComputeDiff ( false ) ;
@@ -232,12 +228,11 @@ export class NotebookEditorSimpleWorker implements IRequestHandler, IDisposable
232
228
const modifiedMetadata = filter ( modified . metadata , key => ! modified . transientDocumentMetadata [ key ] ) ;
233
229
return {
234
230
metadataChanged : JSON . stringify ( originalMetadata ) !== JSON . stringify ( modifiedMetadata ) ,
235
- cellsDiff : await this . $computeDiffWithCellIds ( original , modified ) || diffResult ,
236
- // linesDiff: cellLineChanges
231
+ cellsDiff : this . $computeDiffWithCellIds ( original , modified ) || diffResult ,
237
232
} ;
238
233
}
239
234
240
- async $computeDiffWithCellIds ( original : MirrorNotebookDocument , modified : MirrorNotebookDocument ) : Promise < IDiffResult | undefined > {
235
+ $computeDiffWithCellIds ( original : MirrorNotebookDocument , modified : MirrorNotebookDocument ) : IDiffResult | undefined {
241
236
const originalCellIndexIds = original . cells . map ( ( cell , index ) => ( { index, id : ( cell . metadata ?. id || '' ) as string } ) ) ;
242
237
const modifiedCellIndexIds = modified . cells . map ( ( cell , index ) => ( { index, id : ( cell . metadata ?. id || '' ) as string } ) ) ;
243
238
const originalCellIds = originalCellIndexIds . map ( c => c . id ) ;
@@ -250,18 +245,19 @@ export class NotebookEditorSimpleWorker implements IRequestHandler, IDisposable
250
245
251
246
const diffResult : IDiffResult = { changes : [ ] , quitEarly : false , } ;
252
247
253
- const computeCellHashesById = async ( notebook : MirrorNotebookDocument ) => {
248
+ const computeCellHashesById = ( notebook : MirrorNotebookDocument ) => {
254
249
const hashValue = new Map < string , number > ( ) ;
255
- await Promise . all ( notebook . cells . map ( async ( c , i ) => {
256
- const value = await c . getComparisonValue ( ) ;
250
+ notebook . cells . map ( ( c , i ) => {
251
+ const value = c . getComparisonValue ( ) ;
257
252
// Verified earlier that these cannot be empty.
258
253
const id : string = ( c . metadata ?. id || '' ) as string ;
259
254
hashValue . set ( id , value ) ;
260
- } ) ) ;
255
+ } ) ;
261
256
return hashValue ;
262
257
} ;
263
258
264
- const [ originalSeq , modifiedSeq ] = await Promise . all ( [ computeCellHashesById ( original ) , computeCellHashesById ( modified ) ] ) ;
259
+ const originalSeq = computeCellHashesById ( original ) ;
260
+ const modifiedSeq = computeCellHashesById ( modified ) ;
265
261
266
262
while ( modifiedCellIndexIds . length ) {
267
263
const modifiedCell = modifiedCellIndexIds . shift ( ) ! ;
0 commit comments