summaryrefslogtreecommitdiffstats
path: root/src/corelib/tools/qhash.h
diff options
context:
space:
mode:
authorThorbjørn Martsum <tmartsum@gmail.com>2013-07-12 19:17:33 +0200
committerThe Qt Project <gerrit-noreply@qt-project.org>2013-08-24 15:36:30 +0200
commit93ffb81df6e2cdc57ac8f70c6578f132024d7117 (patch)
tree979931da143ccbfaf567ca6a69c6430db2341f8a /src/corelib/tools/qhash.h
parentdacf9961da86751a59da0e84bc943fe0d1c8d95b (diff)
QHash/QSet - fix QHash::erase when the hash is shared
Before a call to erase on a shared instance would imply that the item was removed from the shared data (i.e all instances) This patch improves the behavior to detach and erase the item specified by the iterator (i.e same behavior as QVector) Since QSet uses QHash it improves QSet the same way. Change-Id: I850b1efcf7bdfc85ceddb23128b048af95f75063 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src/corelib/tools/qhash.h')
-rw-r--r--src/corelib/tools/qhash.h16
1 files changed, 16 insertions, 0 deletions
diff --git a/src/corelib/tools/qhash.h b/src/corelib/tools/qhash.h
index ce9ab33903..3cd967c84b 100644
--- a/src/corelib/tools/qhash.h
+++ b/src/corelib/tools/qhash.h
@@ -850,6 +850,22 @@ Q_OUTOFLINE_TEMPLATE typename QHash<Key, T>::iterator QHash<Key, T>::erase(itera
if (it == iterator(e))
return it;
+ if (d->ref.isShared()) {
+ int bucketNum = (it.i->h % d->numBuckets);
+ const_iterator bucketIterator(*(d->buckets + bucketNum));
+ int stepsFromBucketStartToIte = 0;
+ while (bucketIterator != it) {
+ ++stepsFromBucketStartToIte;
+ ++bucketIterator;
+ }
+ detach();
+ it = iterator(*(d->buckets + bucketNum));
+ while (stepsFromBucketStartToIte > 0) {
+ --stepsFromBucketStartToIte;
+ ++it;
+ }
+ }
+
iterator ret = it;
++ret;