[llvm-commits] [llvm] r152107 - /llvm/trunk/include/llvm/ADT/TinyPtrVector.h
Argyrios Kyrtzidis
akyrtzi at gmail.com
Mon Mar 5 23:14:58 PST 2012
Author: akirtzidis
Date: Tue Mar 6 01:14:58 2012
New Revision: 152107
URL: http://llvm.org/viewvc/llvm-project?rev=152107&view=rev
Log:
[TinyPtrVector] Add erase method and const-goodness.
Modified:
llvm/trunk/include/llvm/ADT/TinyPtrVector.h
Modified: llvm/trunk/include/llvm/ADT/TinyPtrVector.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ADT/TinyPtrVector.h?rev=152107&r1=152106&r2=152107&view=diff
==============================================================================
--- llvm/trunk/include/llvm/ADT/TinyPtrVector.h (original)
+++ llvm/trunk/include/llvm/ADT/TinyPtrVector.h Tue Mar 6 01:14:58 2012
@@ -63,8 +63,10 @@
return Val.template get<VecTy*>()->size();
}
- typedef const EltTy *iterator;
- iterator begin() const {
+ typedef const EltTy *const const_iterator;
+ typedef EltTy *iterator;
+
+ iterator begin() {
if (empty())
return 0;
@@ -74,7 +76,7 @@
return Val.template get<VecTy *>()->begin();
}
- iterator end() const {
+ iterator end() {
if (empty())
return 0;
@@ -84,7 +86,14 @@
return Val.template get<VecTy *>()->end();
}
-
+ const_iterator begin() const {
+ return (const_iterator)const_cast<TinyPtrVector*>(this)->begin();
+ }
+
+ const_iterator end() const {
+ return (const_iterator)const_cast<TinyPtrVector*>(this)->end();
+ }
+
EltTy operator[](unsigned i) const {
assert(!Val.isNull() && "can't index into an empty vector");
if (EltTy V = Val.template dyn_cast<EltTy>()) {
@@ -133,6 +142,20 @@
}
// Otherwise, we're already empty.
}
+
+ iterator erase(iterator I) {
+ // If we have a single value, convert to empty.
+ if (Val.template is<EltTy>()) {
+ if (I == begin())
+ Val = (EltTy)0;
+ } else if (VecTy *Vec = Val.template dyn_cast<VecTy*>()) {
+ // multiple items in a vector; just do the erase, there is no
+ // benefit to collapsing back to a pointer
+ return Vec->erase(I);
+ }
+
+ return 0;
+ }
private:
void operator=(const TinyPtrVector&); // NOT IMPLEMENTED YET.
More information about the llvm-commits
mailing list