From c112b9ce0aa54607c3bbad6db1c21da6bb786b58 Mon Sep 17 00:00:00 2001 From: Argyrios Kyrtzidis Date: Tue, 6 Mar 2012 02:09:28 +0000 Subject: [PATCH] Move clang/Basic/UsuallyTinyPtrVector.h to llvm/ADT/UsuallyTinyPtrVector.h. Depends on llvm commit r152090. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@152091 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/AST/ASTContext.h | 4 +- include/clang/AST/Expr.h | 1 - include/clang/Basic/UsuallyTinyPtrVector.h | 137 --------------------- 3 files changed, 2 insertions(+), 140 deletions(-) delete mode 100644 include/clang/Basic/UsuallyTinyPtrVector.h diff --git a/include/clang/AST/ASTContext.h b/include/clang/AST/ASTContext.h index 5292a05d58..209ab1034f 100644 --- a/include/clang/AST/ASTContext.h +++ b/include/clang/AST/ASTContext.h @@ -20,7 +20,6 @@ #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" @@ -33,6 +32,7 @@ #include "llvm/ADT/IntrusiveRefCntPtr.h" #include "llvm/ADT/OwningPtr.h" #include "llvm/ADT/SmallPtrSet.h" +#include "llvm/ADT/UsuallyTinyPtrVector.h" #include "llvm/Support/Allocator.h" #include @@ -322,7 +322,7 @@ class ASTContext : public RefCountedBase { /// Since most C++ member functions aren't virtual and therefore /// don't override anything, we store the overridden functions in /// this map on the side rather than within the CXXMethodDecl structure. - typedef UsuallyTinyPtrVector CXXMethodVector; + typedef llvm::UsuallyTinyPtrVector CXXMethodVector; llvm::DenseMap OverriddenMethods; /// \brief Mapping from each declaration context to its corresponding lambda diff --git a/include/clang/AST/Expr.h b/include/clang/AST/Expr.h index 5263039da9..075c0a45c3 100644 --- a/include/clang/AST/Expr.h +++ b/include/clang/AST/Expr.h @@ -21,7 +21,6 @@ #include "clang/AST/OperationKinds.h" #include "clang/AST/ASTVector.h" #include "clang/AST/TemplateBase.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/Basic/UsuallyTinyPtrVector.h b/include/clang/Basic/UsuallyTinyPtrVector.h deleted file mode 100644 index 119fab82a8..0000000000 --- a/include/clang/Basic/UsuallyTinyPtrVector.h +++ /dev/null @@ -1,137 +0,0 @@ -//===-- UsuallyTinyPtrVector.h - Pointer vector class -----------*- C++ -*-===// -// -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// -// -// This file defines the UsuallyTinyPtrVector class, which is a vector that -// optimizes the case where there is only one element. -// -//===----------------------------------------------------------------------===// - -#ifndef LLVM_CLANG_BASIC_USUALLY_TINY_PTR_VECTOR_H -#define LLVM_CLANG_BASIC_USUALLY_TINY_PTR_VECTOR_H - -#include - -namespace clang { - -/// \brief A vector class template that is optimized for storing a single -/// pointer element. -template -class UsuallyTinyPtrVector { - /// \brief Storage for the vector. - /// - /// When the low bit is zero, this is a T *. When the - /// low bit is one, this is a std::vector *. - mutable uintptr_t Storage; - - typedef std::vector vector_type; - -public: - UsuallyTinyPtrVector() : Storage(0) { } - explicit UsuallyTinyPtrVector(T *Element) - : Storage(reinterpret_cast(Element)) { } - - bool empty() const { return !Storage; } - - typedef const T **iterator; - iterator begin() const; - iterator end() const; - size_t size() const; - - void push_back(T *Method); - iterator erase(const iterator ElementPos); - void Destroy(); -}; - -template -typename UsuallyTinyPtrVector::iterator -UsuallyTinyPtrVector::begin() const { - if ((Storage & 0x01) == 0) - return reinterpret_cast(&Storage); - - vector_type *Vec = reinterpret_cast(Storage & ~0x01); - return &Vec->front(); -} - -template -typename UsuallyTinyPtrVector::iterator -UsuallyTinyPtrVector::end() const { - if ((Storage & 0x01) == 0) { - if (Storage == 0) - return reinterpret_cast(&Storage); - - return reinterpret_cast(&Storage) + 1; - } - - vector_type *Vec = reinterpret_cast(Storage & ~0x01); - return &Vec->front() + Vec->size(); -} - -template -size_t UsuallyTinyPtrVector::size() const { - if ((Storage & 0x01) == 0) - return (Storage == 0) ? 0 : 1; - - vector_type *Vec = reinterpret_cast(Storage & ~0x01); - return Vec->size(); -} - -template -void UsuallyTinyPtrVector::push_back(T *Element) { - if (Storage == 0) { - // 0 -> 1 element. - Storage = reinterpret_cast(Element); - return; - } - - vector_type *Vec; - if ((Storage & 0x01) == 0) { - // 1 -> 2 elements. Allocate a new vector and push the element into that - // vector. - Vec = new vector_type; - Vec->push_back(reinterpret_cast(Storage)); - Storage = reinterpret_cast(Vec) | 0x01; - } else - Vec = reinterpret_cast(Storage & ~0x01); - - // Add the new element to the vector. - 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) - delete reinterpret_cast(Storage & ~0x01); - - Storage = 0; -} - -} -#endif -- 2.40.0