mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-02-03 00:33:09 +00:00
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:
parent
e19ead0f24
commit
02ee75393f
@ -26,16 +26,17 @@ class StringToOffsetTable {
|
|||||||
std::string AggregateString;
|
std::string AggregateString;
|
||||||
public:
|
public:
|
||||||
|
|
||||||
unsigned GetOrAddStringOffset(StringRef Str) {
|
unsigned GetOrAddStringOffset(StringRef Str, bool appendZero = true) {
|
||||||
unsigned &Entry = StringOffset[Str];
|
StringMapEntry<unsigned> &Entry = StringOffset.GetOrCreateValue(Str, -1U);
|
||||||
if (Entry == 0) {
|
if (Entry.getValue() == -1U) {
|
||||||
// Add the string to the aggregate if this is the first time found.
|
// 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.append(Str.begin(), Str.end());
|
||||||
|
if (appendZero)
|
||||||
AggregateString += '\0';
|
AggregateString += '\0';
|
||||||
}
|
}
|
||||||
|
|
||||||
return Entry;
|
return Entry.getValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
void EmitString(raw_ostream &O) {
|
void EmitString(raw_ostream &O) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user