On Mon, Jul 27, 2015 at 12:27 AM, Kevin Kofler <[email protected]> wrote: > > It doesn't switch the stuff it actually guarantees: > * Moving n elements in the list (for whatever reason) will only move > n*sizeof(void*) bytes (not n*sizeof(T), nor will it call any copy > constructors or destructors).
True, although the not calling constructors/destructors is (should?) also be true for QVector when using Q_MOVABLE_TYPE. (Also nobody says that middle insertions of removals should be "extra cheap"). > * Both prepending and appending is done in amortized O(1) time. Prepending could be achieved for QVector too. But how common is it? > * Accessing the i-th element is performed in guaranteed O(1) time. For "bad" types for QList, that O(1) is hiding two indirections. Only one with QVector. That's a huge cost you're not talking about. > * Inserting an element performs at most 1 heap allocation. (This is the only > performance metric that can change, but the changing from the usual 1 to 0 > is a very welcome optimization for the cases it applies to.) Inserting an element of a wrong type performs *at least* 1 heap allocation. Consider: > ListContainer<WrongType> list; list.reserve(1000); /* insert 1000 elements */ This performs (at least?) 1001 heap allocations with QList and 1 with QVector. -- Giuseppe D'Angelo _______________________________________________ Development mailing list [email protected] http://lists.qt-project.org/mailman/listinfo/development
