summaryrefslogtreecommitdiffstats
path: root/include/clang/Sema/CodeCompleteConsumer.h
diff options
context:
space:
mode:
authorDouglas Gregor <dgregor@apple.com>2011-02-01 23:59:42 +0000
committerDouglas Gregor <dgregor@apple.com>2011-02-01 23:59:42 +0000
commite349d2c61256f11180b7112ab592b4ae700f3dcf (patch)
treedf4b87bd98ec095506f73a06801d22eb3f63f6d6 /include/clang/Sema/CodeCompleteConsumer.h
parent40249e7487c3314f185c63302aaad9edde6dfd53 (diff)
Unique code-completion strings. On Cocoa.h, this costs us about 4% in
speed but saves us about 25% of the memory usage for strings. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@124704 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'include/clang/Sema/CodeCompleteConsumer.h')
-rw-r--r--include/clang/Sema/CodeCompleteConsumer.h38
1 files changed, 38 insertions, 0 deletions
diff --git a/include/clang/Sema/CodeCompleteConsumer.h b/include/clang/Sema/CodeCompleteConsumer.h
index 8cb8e75393..bd9a868101 100644
--- a/include/clang/Sema/CodeCompleteConsumer.h
+++ b/include/clang/Sema/CodeCompleteConsumer.h
@@ -15,7 +15,9 @@
#include "clang/AST/Type.h"
#include "clang/AST/CanonicalType.h"
+#include "llvm/ADT/DenseSet.h"
#include "llvm/ADT/SmallVector.h"
+#include "llvm/ADT/StringExtras.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/Support/Allocator.h"
#include "clang-c/Index.h"
@@ -421,11 +423,47 @@ public:
std::string getAsString() const;
};
+/// \brief \c DenseMap information object for StringRefs.
+struct DenseMapStringRefInfo {
+ static inline llvm::StringRef getEmptyKey() {
+ return llvm::StringRef(reinterpret_cast<const char*>((intptr_t)-1), 0);
+ }
+ static inline llvm::StringRef getTombstoneKey() {
+ return llvm::StringRef(reinterpret_cast<const char *>((intptr_t)-2), 0);
+ }
+ static unsigned getHashValue(llvm::StringRef Str) {
+ return llvm::HashString(Str);
+ }
+ static bool isEqual(llvm::StringRef LHS, llvm::StringRef RHS) {
+ if (LHS.size() == 0 && RHS.size() == 0) {
+ intptr_t LHSVal = reinterpret_cast<intptr_t>(LHS.data());
+ intptr_t RHSVal = reinterpret_cast<intptr_t>(RHS.data());
+ if (LHSVal == -1 || LHSVal == -2 || RHSVal == -1 || RHSVal == -2)
+ return LHSVal == RHSVal;
+
+ return true;
+ }
+
+ return LHS == RHS;
+ }
+};
+
/// \brief An allocator used specifically for the purpose of code completion.
class CodeCompletionAllocator : public llvm::BumpPtrAllocator {
+ llvm::DenseSet<llvm::StringRef, DenseMapStringRefInfo> UniqueStrings;
+ unsigned StringBytesAllocated;
+ unsigned StringBytesUniqued;
+ unsigned StringsAllocated;
+ unsigned StringsUniqued;
+
public:
+ CodeCompletionAllocator();
+ ~CodeCompletionAllocator();
+
/// \brief Copy the given string into this allocator.
const char *CopyString(llvm::StringRef String);
+
+ void PrintStats();
};
/// \brief A builder class used to construct new code-completion strings.