summaryrefslogtreecommitdiffstats
path: root/src/corelib
diff options
context:
space:
mode:
authorJoão Abecasis <joao.abecasis@nokia.com>2012-06-08 17:35:50 +0200
committerQt by Nokia <qt-info@nokia.com>2012-07-03 01:55:39 +0200
commitdeb8d178fe06e3f626f0e7152ac69504094a52a0 (patch)
tree91ded3353deedfdbe5ddc0023857e41672801229 /src/corelib
parent037238022f3a91a5619709b2c7cf4b38cd4d294b (diff)
Add erase operation to QArrayDataOps
Change-Id: I37d3ac465f5beddb5038e22e9cda32acb16c78fc Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src/corelib')
-rw-r--r--src/corelib/tools/qarraydataops.h63
1 files changed, 63 insertions, 0 deletions
diff --git a/src/corelib/tools/qarraydataops.h b/src/corelib/tools/qarraydataops.h
index 088dd2bdee..e4da051742 100644
--- a/src/corelib/tools/qarraydataops.h
+++ b/src/corelib/tools/qarraydataops.h
@@ -117,6 +117,16 @@ struct QPodArrayOps
::memcpy(where, b, (e - b) * sizeof(T));
this->size += (e - b);
}
+
+ void erase(T *b, T *e)
+ {
+ Q_ASSERT(b < e);
+ Q_ASSERT(b >= this->begin() && b < this->end());
+ Q_ASSERT(e > this->begin() && e < this->end());
+
+ ::memmove(b, e, (this->end() - e) * sizeof(T));
+ this->size -= (e - b);
+ }
};
template <class T>
@@ -250,6 +260,25 @@ struct QGenericArrayOps
*writeIter = *e;
}
}
+
+ void erase(T *b, T *e)
+ {
+ Q_ASSERT(b < e);
+ Q_ASSERT(b >= this->begin() && b < this->end());
+ Q_ASSERT(e > this->begin() && e < this->end());
+
+ const T *const end = this->end();
+
+ do {
+ *b = *e;
+ ++b, ++e;
+ } while (e != end);
+
+ do {
+ (--e)->~T();
+ --this->size;
+ } while (e != b);
+ }
};
template <class T>
@@ -324,6 +353,40 @@ struct QMovableArrayOps
displace.commit();
this->size += (e - b);
}
+
+ void erase(T *b, T *e)
+ {
+ Q_ASSERT(b < e);
+ Q_ASSERT(b >= this->begin() && b < this->end());
+ Q_ASSERT(e > this->begin() && e < this->end());
+
+ struct Mover
+ {
+ Mover(T *&start, const T *finish, int &sz)
+ : destination(start)
+ , source(start)
+ , n(finish - start)
+ , size(sz)
+ {
+ }
+
+ ~Mover()
+ {
+ ::memmove(destination, source, n * sizeof(T));
+ size -= (source - destination);
+ }
+
+ T *&destination;
+ const T *const source;
+ size_t n;
+ int &size;
+ } mover(e, this->end(), this->size);
+
+ do {
+ // Exceptions or not, dtor called once per instance
+ (--e)->~T();
+ } while (e != b);
+ }
};
template <class T, class = void>