From f5b132f7b373203eab7cf357b01f935bd88087bd Mon Sep 17 00:00:00 2001
From: Benjamin Kramer <benny.kra@googlemail.com>
Date: Tue, 9 Oct 2012 15:52:25 +0000
Subject: [PATCH] Clearing a SmallPtrSet is still expensive, split it out from
 OverloadCandidateSet::clear and don't do it on destruction.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@165501 91177308-0d34-0410-b5e6-96231b3b80d8
---
 include/clang/Sema/Overload.h | 4 +++-
 lib/Sema/SemaOverload.cpp     | 6 +++++-
 2 files changed, 8 insertions(+), 2 deletions(-)

diff --git a/include/clang/Sema/Overload.h b/include/clang/Sema/Overload.h
index 6ebccbdba6..65ed781f74 100644
--- a/include/clang/Sema/Overload.h
+++ b/include/clang/Sema/Overload.h
@@ -751,9 +751,11 @@ namespace clang {
     OverloadCandidateSet(const OverloadCandidateSet &) LLVM_DELETED_FUNCTION;
     void operator=(const OverloadCandidateSet &) LLVM_DELETED_FUNCTION;
 
+    void destroyCandidates();
+
   public:
     OverloadCandidateSet(SourceLocation Loc) : Loc(Loc), NumInlineSequences(0){}
-    ~OverloadCandidateSet() { clear(); }
+    ~OverloadCandidateSet() { destroyCandidates(); }
 
     SourceLocation getLocation() const { return Loc; }
 
diff --git a/lib/Sema/SemaOverload.cpp b/lib/Sema/SemaOverload.cpp
index 600393137d..bdc25ba39c 100644
--- a/lib/Sema/SemaOverload.cpp
+++ b/lib/Sema/SemaOverload.cpp
@@ -740,13 +740,17 @@ OverloadCandidate::DeductionFailureInfo::getSecondArg() {
   return 0;
 }
 
-void OverloadCandidateSet::clear() {
+void OverloadCandidateSet::destroyCandidates() {
   for (iterator i = begin(), e = end(); i != e; ++i) {
     for (unsigned ii = 0, ie = i->NumConversions; ii != ie; ++ii)
       i->Conversions[ii].~ImplicitConversionSequence();
     if (!i->Viable && i->FailureKind == ovl_fail_bad_deduction)
       i->DeductionFailure.Destroy();
   }
+}
+
+void OverloadCandidateSet::clear() {
+  destroyCandidates();
   NumInlineSequences = 0;
   Candidates.clear();
   Functions.clear();
-- 
2.40.0