From: Argyrios Kyrtzidis Date: Tue, 6 Mar 2012 00:49:28 +0000 (+0000) Subject: Move include/clang/AST/UsuallyTinyPtrVector.h -> include/clang/Basic/UsuallyTinyPtrVe... X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=792777c9028e5fc583a83fb3620c2f9e4f7ed1f9;p=clang Move include/clang/AST/UsuallyTinyPtrVector.h -> include/clang/Basic/UsuallyTinyPtrVector.h and add an erase method to it. Patch by Andrew Craik! git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@152082 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/AST/ASTContext.h b/include/clang/AST/ASTContext.h index 4a5d875373..5292a05d58 100644 --- a/include/clang/AST/ASTContext.h +++ b/include/clang/AST/ASTContext.h @@ -20,6 +20,7 @@ #include "clang/Basic/OperatorKinds.h" #include "clang/Basic/PartialDiagnostic.h" #include "clang/Basic/VersionTuple.h" +#include "clang/Basic/UsuallyTinyPtrVector.h" #include "clang/AST/Decl.h" #include "clang/AST/LambdaMangleContext.h" #include "clang/AST/NestedNameSpecifier.h" @@ -27,7 +28,6 @@ #include "clang/AST/TemplateName.h" #include "clang/AST/Type.h" #include "clang/AST/CanonicalType.h" -#include "clang/AST/UsuallyTinyPtrVector.h" #include "llvm/ADT/DenseMap.h" #include "llvm/ADT/FoldingSet.h" #include "llvm/ADT/IntrusiveRefCntPtr.h" diff --git a/include/clang/AST/Expr.h b/include/clang/AST/Expr.h index 8da780c7a0..5263039da9 100644 --- a/include/clang/AST/Expr.h +++ b/include/clang/AST/Expr.h @@ -21,7 +21,7 @@ #include "clang/AST/OperationKinds.h" #include "clang/AST/ASTVector.h" #include "clang/AST/TemplateBase.h" -#include "clang/AST/UsuallyTinyPtrVector.h" +#include "clang/Basic/UsuallyTinyPtrVector.h" #include "clang/Basic/TargetInfo.h" #include "clang/Basic/TypeTraits.h" #include "llvm/ADT/APSInt.h" diff --git a/include/clang/AST/UsuallyTinyPtrVector.h b/include/clang/Basic/UsuallyTinyPtrVector.h similarity index 75% rename from include/clang/AST/UsuallyTinyPtrVector.h rename to include/clang/Basic/UsuallyTinyPtrVector.h index 534d4d4a36..119fab82a8 100644 --- a/include/clang/AST/UsuallyTinyPtrVector.h +++ b/include/clang/Basic/UsuallyTinyPtrVector.h @@ -12,8 +12,8 @@ // //===----------------------------------------------------------------------===// -#ifndef LLVM_CLANG_AST_USUALLY_TINY_PTR_VECTOR_H -#define LLVM_CLANG_AST_USUALLY_TINY_PTR_VECTOR_H +#ifndef LLVM_CLANG_BASIC_USUALLY_TINY_PTR_VECTOR_H +#define LLVM_CLANG_BASIC_USUALLY_TINY_PTR_VECTOR_H #include @@ -44,6 +44,7 @@ public: size_t size() const; void push_back(T *Method); + iterator erase(const iterator ElementPos); void Destroy(); }; @@ -102,6 +103,28 @@ void UsuallyTinyPtrVector::push_back(T *Element) { Vec->push_back(Element); } +template +typename UsuallyTinyPtrVector::iterator +UsuallyTinyPtrVector::erase( + const typename UsuallyTinyPtrVector::iterator ElementPos) { + // only one item + if ((Storage & 0x01) == 0) { + // if the element is found remove it + if (ElementPos == reinterpret_cast(&Storage)) + Storage = 0; + } else { + // multiple items in a vector; just do the erase, there is no + // benefit to collapsing back to a pointer + vector_type *Vec = reinterpret_cast(Storage & ~0x01); + unsigned index = ElementPos - + const_cast::iterator>(&Vec->front()); + if (index < Vec->size()) + return const_cast::iterator>( + &*(Vec->erase(Vec->begin() + index))); + } + return end(); +} + template void UsuallyTinyPtrVector::Destroy() { if (Storage & 0x01)