summaryrefslogtreecommitdiffstats
path: root/src/gallium/state_trackers/clover/util
diff options
context:
space:
mode:
authorFrancisco Jerez <[email protected]>2014-08-18 08:30:46 +0300
committerFrancisco Jerez <[email protected]>2014-09-05 09:27:20 +0300
commit7c1e6d582c772753cfdbfd3d09509af608b54d91 (patch)
tree19b0f8319356302fc4598361a33d3773205efabc /src/gallium/state_trackers/clover/util
parent995f7b37dad75999ce09f29fe999a8c30e899bb0 (diff)
clover/util: Have compat::vector track separate size and capacity.
In order to make the behaviour of resize() and reserve() closer to the standard. Reported-by: EdB <[email protected]>
Diffstat (limited to 'src/gallium/state_trackers/clover/util')
-rw-r--r--src/gallium/state_trackers/clover/util/compat.hpp67
1 files changed, 42 insertions, 25 deletions
diff --git a/src/gallium/state_trackers/clover/util/compat.hpp b/src/gallium/state_trackers/clover/util/compat.hpp
index 50e1c7d47d5..a4e3938a9f4 100644
--- a/src/gallium/state_trackers/clover/util/compat.hpp
+++ b/src/gallium/state_trackers/clover/util/compat.hpp
@@ -66,65 +66,81 @@ namespace clover {
typedef std::ptrdiff_t difference_type;
typedef std::size_t size_type;
- vector() : p(NULL), n(0) {
+ vector() : p(NULL), _size(0), _capacity(0) {
}
- vector(const vector &v) : p(alloc(v.n, v.p, v.n)), n(v.n) {
+ vector(const vector &v) :
+ p(alloc(v._size, v.p, v._size)),
+ _size(v._size), _capacity(v._size) {
}
- vector(const_iterator p, size_type n) : p(alloc(n, p, n)), n(n) {
+ vector(const_iterator p, size_type n) :
+ p(alloc(n, p, n)), _size(n), _capacity(n) {
}
template<typename C>
vector(const C &v) :
- p(alloc(v.size(), &*v.begin(), v.size())), n(v.size()) {
+ p(alloc(v.size(), &*v.begin(), v.size())),
+ _size(v.size()) , _capacity(v.size()) {
}
~vector() {
- free(n, p);
+ free(_size, p);
}
vector &
operator=(const vector &v) {
- free(n, p);
+ free(_size, p);
- p = alloc(v.n, v.p, v.n);
- n = v.n;
+ p = alloc(v._size, v.p, v._size);
+ _size = v._size;
+ _capacity = v._size;
return *this;
}
void
- reserve(size_type m) {
- if (n < m) {
- T *q = alloc(m, p, n);
- free(n, p);
+ reserve(size_type n) {
+ if (_capacity < n) {
+ T *q = alloc(n, p, _size);
+ free(_size, p);
p = q;
- n = m;
+ _capacity = n;
}
}
void
- resize(size_type m, T x = T()) {
- size_type n = size();
+ resize(size_type n, T x = T()) {
+ if (n <= _size) {
+ for (size_type i = n; i < _size; ++i)
+ p[i].~T();
- reserve(m);
+ } else {
+ reserve(n);
- for (size_type i = n; i < m; ++i)
- new(&p[i]) T(x);
+ for (size_type i = _size; i < n; ++i)
+ new(&p[i]) T(x);
+ }
+
+ _size = n;
}
void
push_back(const T &x) {
- size_type n = size();
- reserve(n + 1);
- new(&p[n]) T(x);
+ reserve(_size + 1);
+ new(&p[_size]) T(x);
+ ++_size;
}
size_type
size() const {
- return n;
+ return _size;
+ }
+
+ size_type
+ capacity() const {
+ return _capacity;
}
iterator
@@ -139,12 +155,12 @@ namespace clover {
iterator
end() {
- return p + n;
+ return p + _size;
}
const_iterator
end() const {
- return p + n;
+ return p + _size;
}
reference
@@ -159,7 +175,8 @@ namespace clover {
private:
iterator p;
- size_type n;
+ size_type _size;
+ size_type _capacity;
};
template<typename T>