8
8
using System . Diagnostics ;
9
9
using System . IO ;
10
10
using System . Text ;
11
+ using System . Linq ;
11
12
12
13
namespace LibObjectFile . Elf
13
14
{
@@ -17,7 +18,7 @@ namespace LibObjectFile.Elf
17
18
public class ElfStringTable : ElfSection
18
19
{
19
20
private readonly MemoryStream _table ;
20
- private readonly List < string > _reservedStrings ;
21
+ private readonly HashSet < string > _reservedStrings ;
21
22
private readonly Dictionary < string , uint > _mapStringToIndex ;
22
23
private readonly Dictionary < uint , string > _mapIndexToString ;
23
24
@@ -36,7 +37,7 @@ public ElfStringTable(int capacityInBytes) : base(ElfSectionType.StringTable)
36
37
_table = new MemoryStream ( capacityInBytes ) ;
37
38
_mapStringToIndex = new Dictionary < string , uint > ( ) ;
38
39
_mapIndexToString = new Dictionary < uint , string > ( ) ;
39
- _reservedStrings = new List < string > ( ) ;
40
+ _reservedStrings = new HashSet < string > ( ) ;
40
41
// Always create an empty string
41
42
CreateIndex ( string . Empty ) ;
42
43
}
@@ -78,7 +79,7 @@ protected override void Write(ElfWriter writer)
78
79
79
80
internal void ReserveString ( string text )
80
81
{
81
- if ( text is object && ! _mapStringToIndex . ContainsKey ( text ) )
82
+ if ( text is object && ! _mapStringToIndex . ContainsKey ( text ) && ! _reservedStrings . Contains ( text ) )
82
83
{
83
84
_reservedStrings . Add ( text ) ;
84
85
}
0 commit comments