[llvm-commits] CVS: llvm/include/llvm/ADT/UniqueVector.h
Chris Lattner
sabre at nondot.org
Mon Feb 5 15:25:04 PST 2007
Changes in directory llvm/include/llvm/ADT:
UniqueVector.h updated: 1.7 -> 1.8
---
Log message:
Simplify this a bit, add an assertion
---
Diffs of the changes: (+10 -11)
UniqueVector.h | 21 ++++++++++-----------
1 files changed, 10 insertions(+), 11 deletions(-)
Index: llvm/include/llvm/ADT/UniqueVector.h
diff -u llvm/include/llvm/ADT/UniqueVector.h:1.7 llvm/include/llvm/ADT/UniqueVector.h:1.8
--- llvm/include/llvm/ADT/UniqueVector.h:1.7 Mon Feb 5 17:18:32 2007
+++ llvm/include/llvm/ADT/UniqueVector.h Mon Feb 5 17:24:48 2007
@@ -27,28 +27,24 @@
// Vector - ID ordered vector of entries. Entries can be indexed by ID - 1.
//
- std::vector<const T *> Vector;
+ std::vector<T> Vector;
public:
/// insert - Append entry to the vector if it doesn't already exist. Returns
/// the entry's index + 1 to be used as a unique ID.
unsigned insert(const T &Entry) {
// Check if the entry is already in the map.
- typename std::map<T, unsigned>::iterator MI = Map.lower_bound(Entry);
+ unsigned &Val = Map[Entry];
// See if entry exists, if so return prior ID.
- if (MI != Map.end() && MI->first == Entry) return MI->second;
+ if (Val) return Val;
// Compute ID for entry.
- unsigned ID = Vector.size() + 1;
-
- // Insert in map.
- MI = Map.insert(MI, std::make_pair(Entry, ID));
+ Val = Vector.size() + 1;
// Insert in vector.
- Vector.push_back(&MI->first);
-
- return ID;
+ Vector.push_back(Entry);
+ return Val;
}
/// idFor - return the ID for an existing entry. Returns 0 if the entry is
@@ -66,7 +62,10 @@
/// operator[] - Returns a reference to the entry with the specified ID.
///
- const T &operator[](unsigned ID) const { return *Vector[ID - 1]; }
+ const T &operator[](unsigned ID) const {
+ assert(ID-1 < size() && "ID is 0 or out of range!");
+ return Vector[ID - 1];
+ }
/// size - Returns the number of entries in the vector.
///
More information about the llvm-commits
mailing list