File tree Expand file tree Collapse file tree 3 files changed +45
-35
lines changed
Expand file tree Collapse file tree 3 files changed +45
-35
lines changed Original file line number Diff line number Diff line change @@ -130,38 +130,4 @@ public override string ToString()
130130 return sb . ToString ( ) ;
131131 }
132132 }
133-
134- public class ScriptureRefComparer : IComparer < ScriptureRef > , IEqualityComparer < ScriptureRef >
135- {
136- public static ScriptureRefComparer Default { get ; } = new ScriptureRefComparer ( compareSegments : true ) ;
137- public static ScriptureRefComparer IgnoreSegments { get ; } = new ScriptureRefComparer ( compareSegments : false ) ;
138- private readonly bool _compareSegments ;
139-
140- public ScriptureRefComparer ( bool compareSegments = true )
141- {
142- _compareSegments = compareSegments ;
143- }
144-
145- public int Compare ( ScriptureRef x , ScriptureRef y )
146- {
147- return x . CompareTo ( y , _compareSegments ) ;
148- }
149-
150- public bool Equals ( ScriptureRef x , ScriptureRef y )
151- {
152- return x . CompareTo ( y , _compareSegments ) == 0 ;
153- }
154-
155- public int GetHashCode ( ScriptureRef obj )
156- {
157- int hashCode = 23 ;
158- hashCode =
159- hashCode * 31
160- + ( _compareSegments ? obj . VerseRef . BBBCCCVVVS . GetHashCode ( ) : obj . VerseRef . BBBCCCVVV . GetHashCode ( ) ) ;
161- hashCode = hashCode * 31 + obj . Versification . GetHashCode ( ) ;
162- // Using ToRelaxed is necessary to maintain equality across relaxed refs, Equals properly handles relaxed ref comparison
163- hashCode = hashCode * 31 + obj . ToRelaxed ( ) . Path . GetSequenceHashCode ( ) ;
164- return hashCode ;
165- }
166- }
167133}
Original file line number Diff line number Diff line change 1+ using System . Collections . Generic ;
2+ using SIL . Extensions ;
3+ using SIL . Machine . Corpora ;
4+
5+ public class ScriptureRefComparer : IComparer < ScriptureRef > , IEqualityComparer < ScriptureRef >
6+ {
7+ public static ScriptureRefComparer Default { get ; } = new ScriptureRefComparer ( compareSegments : true ) ;
8+ public static ScriptureRefComparer IgnoreSegments { get ; } = new ScriptureRefComparer ( compareSegments : false ) ;
9+ private readonly bool _compareSegments ;
10+
11+ public ScriptureRefComparer ( bool compareSegments = true )
12+ {
13+ _compareSegments = compareSegments ;
14+ }
15+
16+ public int Compare ( ScriptureRef x , ScriptureRef y )
17+ {
18+ return x . CompareTo ( y , _compareSegments ) ;
19+ }
20+
21+ public bool Equals ( ScriptureRef x , ScriptureRef y )
22+ {
23+ return x . CompareTo ( y , _compareSegments ) == 0 ;
24+ }
25+
26+ public int GetHashCode ( ScriptureRef obj )
27+ {
28+ int hashCode = 23 ;
29+ hashCode =
30+ hashCode * 31
31+ + ( _compareSegments ? obj . VerseRef . BBBCCCVVVS . GetHashCode ( ) : obj . VerseRef . BBBCCCVVV . GetHashCode ( ) ) ;
32+ hashCode = hashCode * 31 + obj . Versification . GetHashCode ( ) ;
33+ // Using ToRelaxed is necessary to maintain equality across relaxed refs, Equals properly handles relaxed ref comparison
34+ hashCode = hashCode * 31 + obj . ToRelaxed ( ) . Path . GetSequenceHashCode ( ) ;
35+ return hashCode ;
36+ }
37+ }
Original file line number Diff line number Diff line change @@ -81,13 +81,20 @@ public UpdateUsfmParserHandler(
8181 )
8282 {
8383 _rows = rows ?? Array . Empty < UpdateUsfmRow > ( ) ;
84+ _rows = _rows
85+ . Where ( r => r . Refs . Count > 0 )
86+ . OrderBy (
87+ r => r . Refs [ 0 ] ,
88+ compareSegments ? ScriptureRefComparer . Default : ScriptureRefComparer . IgnoreSegments
89+ )
90+ . ToArray ( ) ;
8491 _verseRows = new List < int > ( ) ;
8592 _verseRowsMap = new Dictionary < VerseRef , List < RowInfo > > (
8693 compareSegments ? VerseRefComparer . Default : VerseRefComparer . IgnoreSegments
8794 ) ;
8895 _updateRowsVersification = ScrVers . English ;
8996 if ( _rows . Count > 0 )
90- _updateRowsVersification = _rows . First ( r => r . Refs . Count > 0 ) . Refs [ 0 ] . Versification ;
97+ _updateRowsVersification = _rows [ 0 ] . Refs [ 0 ] . Versification ;
9198 _tokens = new List < UsfmToken > ( ) ;
9299 _updatedText = new List < UsfmToken > ( ) ;
93100 _updateBlocks = new Stack < UsfmUpdateBlock > ( ) ;
You can’t perform that action at this time.
0 commit comments