File tree Expand file tree Collapse file tree 1 file changed +8
-4
lines changed
Expand file tree Collapse file tree 1 file changed +8
-4
lines changed Original file line number Diff line number Diff line change @@ -285,6 +285,7 @@ class Writer {
285285 std::unique_ptr<FileOutputBuffer> &buffer;
286286 std::map<PartialSectionKey, PartialSection *> partialSections;
287287 std::vector<char > strtab;
288+ StringMap<size_t > strtabMap;
288289 std::vector<llvm::object::coff_symbol16> outputSymtab;
289290 std::vector<ECCodeMapEntry> codeMap;
290291 IdataContents idata;
@@ -1439,10 +1440,13 @@ void Writer::assignOutputSectionIndices() {
14391440
14401441size_t Writer::addEntryToStringTable (StringRef str) {
14411442 assert (str.size () > COFF::NameSize);
1442- size_t offsetOfEntry = strtab.size () + 4 ; // +4 for the size field
1443- strtab.insert (strtab.end (), str.begin (), str.end ());
1444- strtab.push_back (' \0 ' );
1445- return offsetOfEntry;
1443+ size_t newOffsetOfEntry = strtab.size () + 4 ; // +4 for the size field
1444+ auto res = strtabMap.try_emplace (str, newOffsetOfEntry);
1445+ if (res.second ) {
1446+ strtab.insert (strtab.end (), str.begin (), str.end ());
1447+ strtab.push_back (' \0 ' );
1448+ }
1449+ return res.first ->getValue ();
14461450}
14471451
14481452std::optional<coff_symbol16> Writer::createSymbol (Defined *def) {
You can’t perform that action at this time.
0 commit comments