@@ -48,17 +48,30 @@ public IEnumerable<string> Sort(
48
48
/// </summary>
49
49
private ushort _lastAvailableId ;
50
50
51
+ private ushort _lastPreAllocatedId ;
52
+
53
+ /// <summary>
54
+ /// Assembly tables context - contains all tables used for building target assembly.
55
+ /// </summary>
56
+ private readonly nanoTablesContext _context ;
57
+
58
+ /// <summary>
59
+ /// Last pre-allocated string identifier.
60
+ /// </summary>
61
+ public ushort LastPreAllocatedId { get => _lastPreAllocatedId ; }
62
+
51
63
/// <summary>
52
64
/// Creates new instance of <see cref="nanoStringTable"/> object.
53
65
/// </summary>
54
66
public nanoStringTable (
67
+ nanoTablesContext context ,
55
68
ICustomStringSorter stringSorter = null )
56
69
{
57
70
GetOrCreateStringId ( string . Empty ) ; // First item in string table always empty string
58
71
_stringSorter = stringSorter ?? new EmptyStringSorter ( ) ;
59
- }
60
72
61
-
73
+ _context = context ;
74
+ }
62
75
63
76
/// <summary>
64
77
/// Gets existing or creates new string reference identifier related to passed string value.
@@ -164,6 +177,46 @@ public void RemoveUnusedItems(HashSet<MetadataToken> items)
164
177
// First item in string table always empty string
165
178
GetOrCreateStringId ( string . Empty ) ;
166
179
180
+ // Pre-allocate strings from some tables
181
+ _context . AssemblyReferenceTable . AllocateStrings ( ) ;
182
+ _context . TypeReferencesTable . AllocateStrings ( ) ;
183
+
184
+
185
+ var memberReferences = _context . AssemblyDefinition . MainModule . GetMemberReferences ( ) ;
186
+ List < MemberReference > memberReferencesInUse = new List < MemberReference > ( ) ;
187
+
188
+ foreach ( var item in memberReferences )
189
+ {
190
+ var memberRef = _context . TypeReferencesTable . Items . FirstOrDefault ( m => m . FullName . Contains ( item . DeclaringType . FullName ) ) ;
191
+ if ( memberRef != null )
192
+ {
193
+ memberReferencesInUse . Add ( item ) ;
194
+ }
195
+ }
196
+
197
+ foreach ( var item in memberReferencesInUse )
198
+ {
199
+ GetOrCreateStringId ( item . Name ) ;
200
+ }
201
+
202
+ foreach ( var item in _context . TypeDefinitionTable . Items )
203
+ {
204
+ GetOrCreateStringId ( item . Namespace ) ;
205
+ GetOrCreateStringId ( item . Name ) ;
206
+
207
+ foreach ( var f in item . Fields )
208
+ {
209
+ GetOrCreateStringId ( f . Name ) ;
210
+ }
211
+
212
+ foreach ( var m in item . Methods )
213
+ {
214
+ GetOrCreateStringId ( m . Name ) ;
215
+ }
216
+ }
217
+
218
+ _lastPreAllocatedId = _idsByStrings . Last ( ) . Value ;
219
+
167
220
// fill in the dictionary with the used strings
168
221
foreach ( var s in usedStrings )
169
222
{
0 commit comments