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

llvm-svn: 151983
This commit is contained in:
Benjamin Kramer 2012-03-03 19:13:20 +00:00
parent 7a3b1d9757
commit dbe7f3bf2e
1 changed files with 7 additions and 6 deletions

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