From dbe7f3bf2efa8fa4f8a9a8d75355f9564a018044 Mon Sep 17 00:00:00 2001 From: Benjamin Kramer Date: Sat, 3 Mar 2012 19:13:20 +0000 Subject: [PATCH] StringToOffsetTable: Allow uniquing the first element, add an option to skip appending a terminating null. llvm-svn: 151983 --- llvm/utils/TableGen/StringToOffsetTable.h | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/llvm/utils/TableGen/StringToOffsetTable.h b/llvm/utils/TableGen/StringToOffsetTable.h index ac9422c5d72d..803f5bd5cf01 100644 --- a/llvm/utils/TableGen/StringToOffsetTable.h +++ b/llvm/utils/TableGen/StringToOffsetTable.h @@ -26,16 +26,17 @@ class StringToOffsetTable { std::string AggregateString; public: - unsigned GetOrAddStringOffset(StringRef Str) { - unsigned &Entry = StringOffset[Str]; - if (Entry == 0) { + unsigned GetOrAddStringOffset(StringRef Str, bool appendZero = true) { + StringMapEntry &Entry = StringOffset.GetOrCreateValue(Str, -1U); + if (Entry.getValue() == -1U) { // Add the string to the aggregate if this is the first time found. - Entry = AggregateString.size(); + Entry.setValue(AggregateString.size()); AggregateString.append(Str.begin(), Str.end()); - AggregateString += '\0'; + if (appendZero) + AggregateString += '\0'; } - return Entry; + return Entry.getValue(); } void EmitString(raw_ostream &O) {