diff options
author | Argyrios Kyrtzidis <akyrtzi@gmail.com> | 2012-03-06 00:49:28 +0000 |
---|---|---|
committer | Argyrios Kyrtzidis <akyrtzi@gmail.com> | 2012-03-06 00:49:28 +0000 |
commit | 792777c9028e5fc583a83fb3620c2f9e4f7ed1f9 (patch) | |
tree | 04a25a28edb710627a122f551633a18b7137d4ab | |
parent | 218fce0f113f82fc28f2fb0c4b555ae2901b8a93 (diff) |
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
-rw-r--r-- | include/clang/AST/ASTContext.h | 2 | ||||
-rw-r--r-- | include/clang/AST/Expr.h | 2 | ||||
-rw-r--r-- | include/clang/Basic/UsuallyTinyPtrVector.h (renamed from include/clang/AST/UsuallyTinyPtrVector.h) | 27 |
3 files changed, 27 insertions, 4 deletions
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 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 <vector> @@ -44,6 +44,7 @@ public: size_t size() const; void push_back(T *Method); + iterator erase(const iterator ElementPos); void Destroy(); }; @@ -103,6 +104,28 @@ void UsuallyTinyPtrVector<T>::push_back(T *Element) { } template<typename T> +typename UsuallyTinyPtrVector<T>::iterator +UsuallyTinyPtrVector<T>::erase( + const typename UsuallyTinyPtrVector<T>::iterator ElementPos) { + // only one item + if ((Storage & 0x01) == 0) { + // if the element is found remove it + if (ElementPos == reinterpret_cast<T **>(&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<vector_type *>(Storage & ~0x01); + unsigned index = ElementPos - + const_cast<typename UsuallyTinyPtrVector<T>::iterator>(&Vec->front()); + if (index < Vec->size()) + return const_cast<typename UsuallyTinyPtrVector<T>::iterator>( + &*(Vec->erase(Vec->begin() + index))); + } + return end(); +} + +template<typename T> void UsuallyTinyPtrVector<T>::Destroy() { if (Storage & 0x01) delete reinterpret_cast<vector_type *>(Storage & ~0x01); |