]> granicus.if.org Git - clang/commitdiff
Move include/clang/AST/UsuallyTinyPtrVector.h -> include/clang/Basic/UsuallyTinyPtrVe...
authorArgyrios Kyrtzidis <akyrtzi@gmail.com>
Tue, 6 Mar 2012 00:49:28 +0000 (00:49 +0000)
committerArgyrios Kyrtzidis <akyrtzi@gmail.com>
Tue, 6 Mar 2012 00:49:28 +0000 (00:49 +0000)
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

include/clang/AST/ASTContext.h
include/clang/AST/Expr.h
include/clang/Basic/UsuallyTinyPtrVector.h [moved from include/clang/AST/UsuallyTinyPtrVector.h with 75% similarity]

index 4a5d8753739c12e09ad61d69ad20f66d432573ee..5292a05d584febb0b571bd437edb209d02c71715 100644 (file)
@@ -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"
index 8da780c7a04d5b7a37ca0bf8a6408f1b16147881..5263039da965da9050158ae0e62c36e9541feb0c 100644 (file)
@@ -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"
similarity index 75%
rename from include/clang/AST/UsuallyTinyPtrVector.h
rename to include/clang/Basic/UsuallyTinyPtrVector.h
index 534d4d4a367f777d75edf666ce1301fed4a2d9ed..119fab82a89d6214d96be208265008fc76152a1f 100644 (file)
@@ -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();
 };
 
@@ -102,6 +103,28 @@ void UsuallyTinyPtrVector<T>::push_back(T *Element) {
   Vec->push_back(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)