#ifndef LLVM_SUPPORT_STRINGSAVER_H
#define LLVM_SUPPORT_STRINGSAVER_H
-#include "llvm/ADT/DenseSet.h"
+#include "llvm/ADT/StringSet.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/ADT/Twine.h"
#include "llvm/Support/Allocator.h"
///
/// Compared to StringSaver, it does more work but avoids saving the same string
/// multiple times.
-///
-/// Compared to StringPool, it performs fewer allocations but doesn't support
-/// refcounting/deletion.
class UniqueStringSaver final {
- StringSaver Strings;
- llvm::DenseSet<llvm::StringRef> Unique;
+ StringSet<BumpPtrAllocator &> Strings;
public:
UniqueStringSaver(BumpPtrAllocator &Alloc) : Strings(Alloc) {}
}
StringRef UniqueStringSaver::save(StringRef S) {
- auto R = Unique.insert(S);
- if (R.second) // cache miss, need to actually save the string
- *R.first = Strings.save(S); // safe replacement with equal value
- return *R.first;
+ return Strings.insert(S).first->getKey();
}