aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorlloyd <[email protected]>2010-09-09 14:01:53 +0000
committerlloyd <[email protected]>2010-09-09 14:01:53 +0000
commit464c0275c90b2e8f999e3c77d3d5be79ac5bfe70 (patch)
tree62bd1eadae227b8e8c0f7cdfea7522141c04bec2
parentd6c39e385e105da61797695c0583dd796e5af965 (diff)
Use a true lexicographic ordering in MemoryRegion::operator<
-rw-r--r--src/alloc/secmem.h19
1 files changed, 11 insertions, 8 deletions
diff --git a/src/alloc/secmem.h b/src/alloc/secmem.h
index 117b8754f..f7aa6f3d1 100644
--- a/src/alloc/secmem.h
+++ b/src/alloc/secmem.h
@@ -81,8 +81,8 @@ class MemoryRegion
}
/**
- * Compare two buffers lexicographically.
- * @return true if this buffer is lexicographically smaller than other.
+ * Compare two buffers
+ * @return true iff this is ordered before other
*/
bool operator<(const MemoryRegion<T>& other) const;
@@ -245,16 +245,19 @@ void MemoryRegion<T>::resize(u32bit n)
template<typename T>
bool MemoryRegion<T>::operator<(const MemoryRegion<T>& other) const
{
- if(size() < other.size()) return true;
- if(size() > other.size()) return false;
+ const u32bit min_size = std::min(size(), other.size());
- for(u32bit j = 0; j != size(); j++)
+ // This should probably be rewritten to run in constant time
+ for(u32bit i = 0; i != min_size; ++i)
{
- if(buf[j] < other[j]) return true;
- if(buf[j] > other[j]) return false;
+ if(buf[i] < other[i])
+ return true;
+ if(buf[i] > other[i])
+ return false;
}
- return false;
+ // First min_size bytes are equal, shorter is first
+ return (size() < other.size());
}
/*