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 4a5d875..5292a05 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 8da780c..5263039 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 534d4d4..119fab8 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 @@
   size_t size() const;
 
   void push_back(T *Method);
+  iterator erase(const iterator ElementPos);
   void Destroy();
 };
 
@@ -103,6 +104,28 @@
 }
 
 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);