From 6159d0fe2d40708b5a3caab91c8292253894ebf3 Mon Sep 17 00:00:00 2001 From: Douglas Gregor Date: Wed, 2 Feb 2011 19:04:30 +0000 Subject: [PATCH] Revert r124704, which uniqued code-completion strings. The space savings of 25% sounds impressive, except that this amounted to only about 360k in our standard "large" completion result set (40,000 results). Since code completion is performance-sensitive, the 4% slowdown due to uniquing outweighs the 360k benefit. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@124737 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/Sema/CodeCompleteConsumer.h | 38 ----------------------- lib/Sema/CodeCompleteConsumer.cpp | 31 ------------------ 2 files changed, 69 deletions(-) diff --git a/include/clang/Sema/CodeCompleteConsumer.h b/include/clang/Sema/CodeCompleteConsumer.h index bd9a868101..8cb8e75393 100644 --- a/include/clang/Sema/CodeCompleteConsumer.h +++ b/include/clang/Sema/CodeCompleteConsumer.h @@ -15,9 +15,7 @@ #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" @@ -423,47 +421,11 @@ public: std::string getAsString() const; }; -/// \brief \c DenseMap information object for StringRefs. -struct DenseMapStringRefInfo { - static inline llvm::StringRef getEmptyKey() { - return llvm::StringRef(reinterpret_cast((intptr_t)-1), 0); - } - static inline llvm::StringRef getTombstoneKey() { - return llvm::StringRef(reinterpret_cast((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(LHS.data()); - intptr_t RHSVal = reinterpret_cast(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 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. diff --git a/lib/Sema/CodeCompleteConsumer.cpp b/lib/Sema/CodeCompleteConsumer.cpp index 572c8dcbd0..cb2dd234b4 100644 --- a/lib/Sema/CodeCompleteConsumer.cpp +++ b/lib/Sema/CodeCompleteConsumer.cpp @@ -220,41 +220,10 @@ const char *CodeCompletionString::getTypedText() const { return 0; } -CodeCompletionAllocator::CodeCompletionAllocator() - : llvm::BumpPtrAllocator(), StringBytesAllocated(0), StringBytesUniqued(0), - StringsAllocated(0), StringsUniqued(0) -{ -} - -CodeCompletionAllocator::~CodeCompletionAllocator() { } - -void CodeCompletionAllocator::PrintStats() { - llvm::errs() << "---Code completion memory allocation---\n" - << "String bytes uniqued: " << StringBytesUniqued << "/" - << StringBytesAllocated << " (" - << ((float)StringBytesUniqued*100/StringBytesAllocated) - << ")\nStrings uniqued: " << StringsUniqued << "/" << StringsAllocated - << " (" << ((float)StringsUniqued*100/StringsAllocated) - << ")\n"; - - llvm::BumpPtrAllocator::PrintStats(); -} - const char *CodeCompletionAllocator::CopyString(llvm::StringRef String) { - llvm::DenseSet::iterator Uniqued - = UniqueStrings.find(String); - ++StringsAllocated; - StringBytesAllocated += String.size() + 1; - if (Uniqued != UniqueStrings.end()) { - StringBytesUniqued += String.size() + 1; - ++StringsUniqued; - return Uniqued->data(); - } - char *Mem = (char *)Allocate(String.size() + 1, 1); std::copy(String.begin(), String.end(), Mem); Mem[String.size()] = 0; - UniqueStrings.insert(llvm::StringRef(Mem, String.size())); return Mem; } -- 2.40.0