[cfe-commits] r152082 - in /cfe/trunk/include/clang: AST/ASTContext.h AST/Expr.h AST/UsuallyTinyPtrVector.h Basic/UsuallyTinyPtrVector.h
Argyrios Kyrtzidis
akyrtzi at gmail.com
Mon Mar 5 16:49:28 PST 2012
Author: akirtzidis
Date: Mon Mar 5 18:49:28 2012
New Revision: 152082
URL: http://llvm.org/viewvc/llvm-project?rev=152082&view=rev
Log:
Move include/clang/AST/UsuallyTinyPtrVector.h -> include/clang/Basic/UsuallyTinyPtrVector.h
and add an erase method to it.
Patch by Andrew Craik!
Added:
cfe/trunk/include/clang/Basic/UsuallyTinyPtrVector.h
- copied, changed from r152075, cfe/trunk/include/clang/AST/UsuallyTinyPtrVector.h
Removed:
cfe/trunk/include/clang/AST/UsuallyTinyPtrVector.h
Modified:
cfe/trunk/include/clang/AST/ASTContext.h
cfe/trunk/include/clang/AST/Expr.h
Modified: cfe/trunk/include/clang/AST/ASTContext.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/ASTContext.h?rev=152082&r1=152081&r2=152082&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/ASTContext.h (original)
+++ cfe/trunk/include/clang/AST/ASTContext.h Mon Mar 5 18:49:28 2012
@@ -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"
Modified: cfe/trunk/include/clang/AST/Expr.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Expr.h?rev=152082&r1=152081&r2=152082&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/Expr.h (original)
+++ cfe/trunk/include/clang/AST/Expr.h Mon Mar 5 18:49:28 2012
@@ -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"
Removed: cfe/trunk/include/clang/AST/UsuallyTinyPtrVector.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/UsuallyTinyPtrVector.h?rev=152081&view=auto
==============================================================================
--- cfe/trunk/include/clang/AST/UsuallyTinyPtrVector.h (original)
+++ cfe/trunk/include/clang/AST/UsuallyTinyPtrVector.h (removed)
@@ -1,114 +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_AST_USUALLY_TINY_PTR_VECTOR_H
-#define LLVM_CLANG_AST_USUALLY_TINY_PTR_VECTOR_H
-
-#include <vector>
-
-namespace clang {
-
-/// \brief A vector class template that is optimized for storing a single
-/// pointer element.
-template<typename T>
-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<T *> *.
- mutable uintptr_t Storage;
-
- typedef std::vector<T*> vector_type;
-
-public:
- UsuallyTinyPtrVector() : Storage(0) { }
- explicit UsuallyTinyPtrVector(T *Element)
- : Storage(reinterpret_cast<uintptr_t>(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);
- void Destroy();
-};
-
-template<typename T>
-typename UsuallyTinyPtrVector<T>::iterator
-UsuallyTinyPtrVector<T>::begin() const {
- if ((Storage & 0x01) == 0)
- return reinterpret_cast<iterator>(&Storage);
-
- vector_type *Vec = reinterpret_cast<vector_type *>(Storage & ~0x01);
- return &Vec->front();
-}
-
-template<typename T>
-typename UsuallyTinyPtrVector<T>::iterator
-UsuallyTinyPtrVector<T>::end() const {
- if ((Storage & 0x01) == 0) {
- if (Storage == 0)
- return reinterpret_cast<iterator>(&Storage);
-
- return reinterpret_cast<iterator>(&Storage) + 1;
- }
-
- vector_type *Vec = reinterpret_cast<vector_type *>(Storage & ~0x01);
- return &Vec->front() + Vec->size();
-}
-
-template<typename T>
-size_t UsuallyTinyPtrVector<T>::size() const {
- if ((Storage & 0x01) == 0)
- return (Storage == 0) ? 0 : 1;
-
- vector_type *Vec = reinterpret_cast<vector_type *>(Storage & ~0x01);
- return Vec->size();
-}
-
-template<typename T>
-void UsuallyTinyPtrVector<T>::push_back(T *Element) {
- if (Storage == 0) {
- // 0 -> 1 element.
- Storage = reinterpret_cast<uintptr_t>(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<T *>(Storage));
- Storage = reinterpret_cast<uintptr_t>(Vec) | 0x01;
- } else
- Vec = reinterpret_cast<vector_type *>(Storage & ~0x01);
-
- // Add the new element to the vector.
- Vec->push_back(Element);
-}
-
-template<typename T>
-void UsuallyTinyPtrVector<T>::Destroy() {
- if (Storage & 0x01)
- delete reinterpret_cast<vector_type *>(Storage & ~0x01);
-
- Storage = 0;
-}
-
-}
-#endif
Copied: cfe/trunk/include/clang/Basic/UsuallyTinyPtrVector.h (from r152075, cfe/trunk/include/clang/AST/UsuallyTinyPtrVector.h)
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/UsuallyTinyPtrVector.h?p2=cfe/trunk/include/clang/Basic/UsuallyTinyPtrVector.h&p1=cfe/trunk/include/clang/AST/UsuallyTinyPtrVector.h&r1=152075&r2=152082&rev=152082&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/UsuallyTinyPtrVector.h (original)
+++ cfe/trunk/include/clang/Basic/UsuallyTinyPtrVector.h Mon Mar 5 18:49:28 2012
@@ -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);
More information about the cfe-commits
mailing list