diff options
author | Thiago Macieira <thiago.macieira@intel.com> | 2014-09-22 15:18:38 -0700 |
---|---|---|
committer | Marc Mutz <marc.mutz@kdab.com> | 2015-07-29 08:46:19 +0000 |
commit | 2d981e7e9fc2d55b1615332db7571786438158f6 (patch) | |
tree | 8a83031db8ce621b470bb0aa8e66712bea896593 /examples | |
parent | d7e23c1011df3390c42d67436d81ce73c736843c (diff) |
Refactor QVersionNumber so it stores values in-class
The common case of QVersionNumber is that there are few segments and
each segment is a small integers. So instead of allocating a
QVector<int>, just store those numbers in the class itself if
possible. Think of this as a "Small String Optimization" for
QVersionNumber.
QVector<int> costs 16 + 4*N bytes, plus malloc overhead. After this
change, QVersionNumber(5,4,0) will have an overhead of zero.
The memory layout is explained in the header. I've coded it so big
endian also works, but I have not tested it at all.
Aside from the special functions for QVersionNumber and operator>>, all
the rest of the algorithm could have been left unchanged. I only updated
segments(), normalized(), compare(), commonPrefix() and fromString() to
take advantage of the smaller implementation in a more efficient way.
Note: QVersionNumber's constructors often leave half of the object or
more uninitialized. That's not a problem.
Change-Id: I4a2a0ce09fce2580f02d678e2f80b1dba74bac9d
Reviewed-by: Marc Mutz <marc.mutz@kdab.com>
Diffstat (limited to 'examples')
0 files changed, 0 insertions, 0 deletions