@@ -108,6 +108,10 @@ static nanoSignaturesTable()
108
108
/// </summary>
109
109
private readonly IDictionary < byte [ ] , ushort > _idsBySignatures =
110
110
new Dictionary < byte [ ] , ushort > ( new ByteArrayComparer ( ) ) ;
111
+ /// <summary>
112
+ /// The signatures as they are written to the output stream.
113
+ /// </summary>
114
+ private readonly List < byte > _signatureTable = new List < byte > ( ) ;
111
115
112
116
/// <summary>
113
117
/// Assembly tables context - contains all tables used for building target assembly.
@@ -116,11 +120,6 @@ static nanoSignaturesTable()
116
120
117
121
private readonly bool _verbose = false ;
118
122
119
- /// <summary>
120
- /// Last available signature id (offset in resulting table).
121
- /// </summary>
122
- private ushort _lastAvailableId ;
123
-
124
123
/// <summary>
125
124
/// Creates new instance of <see cref="nanoSignaturesTable"/> object.
126
125
/// </summary>
@@ -468,12 +467,7 @@ public void WriteDataTypeForTypeDef(TypeDefinition typeDefinition, nanoBinaryWri
468
467
public void Write (
469
468
nanoBinaryWriter writer )
470
469
{
471
- foreach ( var signature in _idsBySignatures
472
- . OrderBy ( item => item . Value )
473
- . Select ( item => item . Key ) )
474
- {
475
- writer . WriteBytes ( signature ) ;
476
- }
470
+ writer . WriteBytes ( _signatureTable . ToArray ( ) ) ;
477
471
}
478
472
479
473
private byte [ ] GetSignature (
@@ -736,18 +730,29 @@ private ushort GetOrCreateSignatureIdImpl(
736
730
return id ;
737
731
}
738
732
739
- var fullSignatures = GetFullSignaturesArray ( ) ;
740
- for ( var i = 0 ; i <= fullSignatures . Length - signature . Length ; ++ i )
733
+ for ( int i = 0 ; i < _signatureTable . Count - signature . Length ; i ++ )
741
734
{
742
- if ( signature . SequenceEqual ( fullSignatures . Skip ( i ) . Take ( signature . Length ) ) )
735
+ bool found = true ;
736
+ for ( int j = 0 ; j < signature . Length ; ++ j )
743
737
{
744
- return ( ushort ) i ;
738
+ if ( _signatureTable [ i + j ] != signature [ j ] )
739
+ {
740
+ found = false ;
741
+ break ;
742
+ }
743
+ }
744
+
745
+ if ( found )
746
+ {
747
+ id = ( ushort ) i ;
748
+ _idsBySignatures . Add ( signature , id ) ;
749
+ return id ;
745
750
}
746
751
}
747
752
748
- id = _lastAvailableId ;
753
+ id = ( ushort ) _signatureTable . Count ;
749
754
_idsBySignatures . Add ( signature , id ) ;
750
- _lastAvailableId += ( ushort ) signature . Length ;
755
+ _signatureTable . AddRange ( signature ) ;
751
756
752
757
return id ;
753
758
}
@@ -775,20 +780,6 @@ private void WriteTypeInfo(
775
780
}
776
781
}
777
782
778
- private byte [ ] GetFullSignaturesArray ( )
779
- {
780
- return _idsBySignatures
781
- . OrderBy ( item => item . Value )
782
- . Select ( item => item . Key )
783
- . Aggregate ( new List < byte > ( ) ,
784
- ( current , item ) =>
785
- {
786
- current . AddRange ( item ) ;
787
- return current ;
788
- } )
789
- . ToArray ( ) ;
790
- }
791
-
792
783
private void WriteSubTypeInfo ( TypeReference typeDefinition , nanoBinaryWriter writer )
793
784
{
794
785
ushort referenceId ;
0 commit comments