summaryrefslogtreecommitdiffstats
path: root/src/corelib/tools/qarraydata.cpp
diff options
context:
space:
mode:
authorMårten Nordheim <marten.nordheim@qt.io>2019-08-28 17:44:20 +0200
committerMårten Nordheim <marten.nordheim@qt.io>2019-08-30 14:33:06 +0200
commite75c691d073a1e627db29294a0c12a55c67e3e49 (patch)
tree46ca60f5ab47e9a67536643fdb334e962896f6b6 /src/corelib/tools/qarraydata.cpp
parent64ed4081cabf039e0132e9359649a6e5599f54cc (diff)
QArrayData: Don't allocate space we cannot use
When reallocating we assume we will grow more and increase the size to the next power of 2. However, this might be a size where we end up with space we cannot take advantage of. Such as having 4 bytes free at the tail when we have 8 byte objects. The larger the objects are the greater the chance is that we will end up in this situation, and it would have a greater chance to leave big allocated chunks unused. Change-Id: Ifea3d92763c1bafd489b66605c741447e5a57d5a Reviewed-by: Edward Welbourne <edward.welbourne@qt.io> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src/corelib/tools/qarraydata.cpp')
-rw-r--r--src/corelib/tools/qarraydata.cpp2
1 files changed, 1 insertions, 1 deletions
diff --git a/src/corelib/tools/qarraydata.cpp b/src/corelib/tools/qarraydata.cpp
index 234a44f6b6..36a221f728 100644
--- a/src/corelib/tools/qarraydata.cpp
+++ b/src/corelib/tools/qarraydata.cpp
@@ -143,7 +143,7 @@ qCalculateGrowingBlockSize(size_t elementCount, size_t elementSize, size_t heade
}
result.elementCount = (bytes - unsigned(headerSize)) / unsigned(elementSize);
- result.size = bytes;
+ result.size = result.elementCount * elementSize + headerSize;
return result;
}