From bd6784b57909a87134c8bb5ddec73b27b8f1260b Mon Sep 17 00:00:00 2001 From: Andrei Golubev Date: Wed, 4 Nov 2020 16:56:53 +0100 Subject: [PATCH] Simplify Q*ArrayOps emplace() signature Template type never would've worked, really. We relied everywhere that 'iterator' is comparable to our iterators (in generic version it should be even the same type - see std::rotate API) and the iterator type is castable to T* in POD and Movable cases, so simplify that, no need for extra template boilerplate Change-Id: I263ae2ba90ca27abceca01fcc21d80a350bbd743 Reviewed-by: Lars Knoll Reviewed-by: Thiago Macieira --- src/corelib/tools/qarraydataops.h | 37 +++++++++++++++---------------- 1 file changed, 18 insertions(+), 19 deletions(-) diff --git a/src/corelib/tools/qarraydataops.h b/src/corelib/tools/qarraydataops.h index 1fd7e99c42..2162512883 100644 --- a/src/corelib/tools/qarraydataops.h +++ b/src/corelib/tools/qarraydataops.h @@ -356,7 +356,6 @@ public: *where++ = t; } - template void emplace(T *where, Args&&... args) { emplace(GrowsForwardTag{}, where, std::forward(args)...); } @@ -760,13 +759,12 @@ public: } } - - template - void emplace(iterator where, Args&&... args) + template + void emplace(T *where, Args &&... args) { emplace(GrowsForwardTag{}, where, std::forward(args)...); } - template - void emplace(GrowsForwardTag, iterator where, Args&&... args) + template + void emplace(GrowsForwardTag, T *where, Args &&... args) { Q_ASSERT(!this->isShared()); Q_ASSERT(where >= this->begin() && where <= this->end()); @@ -799,8 +797,8 @@ public: } } - template - void emplace(GrowsBackwardsTag, iterator where, Args&&... args) + template + void emplace(GrowsBackwardsTag, T *where, Args &&... args) { Q_ASSERT(!this->isShared()); Q_ASSERT(where >= this->begin() && where <= this->end()); @@ -1043,14 +1041,14 @@ public: // use moving insert using QGenericArrayOps::insert; - template - void emplace(iterator where, Args &&... args) + template + void emplace(T *where, Args &&... args) { emplace(GrowsForwardTag {}, where, std::forward(args)...); } - template - void emplace(GrowsForwardTag, iterator where, Args &&... args) + template + void emplace(GrowsForwardTag, T *where, Args &&... args) { Q_ASSERT(!this->isShared()); Q_ASSERT(where >= this->begin() && where <= this->end()); @@ -1068,8 +1066,8 @@ public: ++this->size; } - template - void emplace(GrowsBackwardsTag, iterator where, Args &&... args) + template + void emplace(GrowsBackwardsTag, T *where, Args &&... args) { Q_ASSERT(!this->isShared()); Q_ASSERT(where >= this->begin() && where <= this->end()); @@ -1367,18 +1365,19 @@ public: } - - template - void emplace(iterator where, Args&&... args) + template + void emplace(T *where, Args &&... args) { Q_ASSERT(!this->isShared()); Q_ASSERT(where >= this->begin() && where <= this->end()); Q_ASSERT(this->allocatedCapacity() - this->size >= 1); + const T *begin = this->begin(); + const T *end = this->end(); // Qt5 QList in insert(1): try to move less data around // Now: - const bool shouldInsertAtBegin = (where - this->begin()) < (this->end() - where) - || this->freeSpaceAtEnd() <= 0; + const bool shouldInsertAtBegin = + (where - begin) < (end - where) || this->freeSpaceAtEnd() <= 0; if (this->freeSpaceAtBegin() > 0 && shouldInsertAtBegin) { Base::emplace(GrowsBackwardsTag{}, where, std::forward(args)...); } else {