StringToOffsetTable: Allow uniquing the first element, add an option to skip appending a terminating null.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@151983 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Benjamin Kramer 2012-03-03 19:13:20 +00:00
parent e19ead0f24
commit 02ee75393f

View File

@ -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<unsigned> &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());
if (appendZero)
AggregateString += '\0';
}
return Entry;
return Entry.getValue();
}
void EmitString(raw_ostream &O) {