88using System . Diagnostics ;
99using System . IO ;
1010using System . Text ;
11+ using System . Linq ;
1112
1213namespace LibObjectFile . Elf
1314{
@@ -17,7 +18,7 @@ namespace LibObjectFile.Elf
1718 public class ElfStringTable : ElfSection
1819 {
1920 private readonly MemoryStream _table ;
20- private readonly List < string > _reservedStrings ;
21+ private readonly HashSet < string > _reservedStrings ;
2122 private readonly Dictionary < string , uint > _mapStringToIndex ;
2223 private readonly Dictionary < uint , string > _mapIndexToString ;
2324
@@ -36,7 +37,7 @@ public ElfStringTable(int capacityInBytes) : base(ElfSectionType.StringTable)
3637 _table = new MemoryStream ( capacityInBytes ) ;
3738 _mapStringToIndex = new Dictionary < string , uint > ( ) ;
3839 _mapIndexToString = new Dictionary < uint , string > ( ) ;
39- _reservedStrings = new List < string > ( ) ;
40+ _reservedStrings = new HashSet < string > ( ) ;
4041 // Always create an empty string
4142 CreateIndex ( string . Empty ) ;
4243 }
@@ -78,7 +79,7 @@ protected override void Write(ElfWriter writer)
7879
7980 internal void ReserveString ( string text )
8081 {
81- if ( text is object && ! _mapStringToIndex . ContainsKey ( text ) )
82+ if ( text is object && ! _mapStringToIndex . ContainsKey ( text ) && ! _reservedStrings . Contains ( text ) )
8283 {
8384 _reservedStrings . Add ( text ) ;
8485 }
0 commit comments