66import { IDiffChange , ISequence , LcsDiff } from 'vs/base/common/diff/diff' ;
77import * as strings from 'vs/base/common/strings' ;
88import { ICharChange , ILineChange } from 'vs/editor/common/editorCommon' ;
9+ import { hash } from 'vs/base/common/hash' ;
910
1011const MAXIMUM_RUN_TIME = 5000 ; // 5 seconds
1112const MINIMUM_MATCHING_CHARACTER_LENGTH = 3 ;
@@ -19,17 +20,20 @@ class LineSequence implements ISequence {
1920
2021 private readonly _lines : string [ ] ;
2122 private readonly _trimmedLines : string [ ] ;
23+ private readonly _trimmedLinesHash : number [ ] ;
2224 private readonly _startColumns : number [ ] ;
2325 private readonly _endColumns : number [ ] ;
2426
2527 constructor ( lines : string [ ] ) {
2628 let startColumns : number [ ] = [ ] ;
2729 let endColumns : number [ ] = [ ] ;
2830 this . _trimmedLines = [ ] ;
31+ this . _trimmedLinesHash = [ ] ;
2932 for ( let i = 0 , length = lines . length ; i < length ; i ++ ) {
3033 startColumns [ i ] = getFirstNonBlankColumn ( lines [ i ] , 1 ) ;
3134 endColumns [ i ] = getLastNonBlankColumn ( lines [ i ] , 1 ) ;
3235 this . _trimmedLines [ i ] = lines [ i ] . substring ( startColumns [ i ] - 1 , endColumns [ i ] - 1 ) ;
36+ this . _trimmedLinesHash [ i ] = hash ( this . _trimmedLines [ i ] ) ;
3337 }
3438 this . _lines = lines ;
3539 this . _startColumns = startColumns ;
@@ -44,6 +48,14 @@ class LineSequence implements ISequence {
4448 return this . _trimmedLines [ i ] ;
4549 }
4650
51+ public elementsAreEqual ( seq1 : LineSequence , index1 : number , seq2 : LineSequence , index2 : number ) : boolean {
52+ if ( seq1 . _trimmedLinesHash [ index1 ] === seq2 . _trimmedLinesHash [ index2 ] ) {
53+ // hashes are equal
54+ return seq1 . _trimmedLines [ index1 ] === seq2 . _trimmedLines [ index2 ] ;
55+ }
56+ return false ;
57+ }
58+
4759 public getStartLineNumber ( i : number ) : number {
4860 return i + 1 ;
4961 }
@@ -92,6 +104,10 @@ class CharSequence implements ISequence {
92104 return this . _charCodes [ i ] ;
93105 }
94106
107+ public elementsAreEqual ( seq1 : CharSequence , index1 : number , seq2 : CharSequence , index2 : number ) : boolean {
108+ return ( seq1 . getElementAtIndex ( index1 ) === seq2 . getElementAtIndex ( index2 ) ) ;
109+ }
110+
95111 public getStartLineNumber ( i : number ) : number {
96112 return this . _lineNumbers [ i ] ;
97113 }
0 commit comments