Commit 76a7dff8 authored by Marco Bubke's avatar Marco Bubke

Utils: Simplify SmallString reserve

The reserve function is quite complicated because it is implementing a
grow pattern. Something we seldom need. So we now align to the next cache
line size.

Change-Id: I14bb88c12bd740a7afa7cd08969a4e07fb0f9add
Reviewed-by: Tim Jenssen's avatarTim Jenssen <tim.jenssen@qt.io>
parent e255baaa
......@@ -658,18 +658,9 @@ unittest_public:
{
const size_type cacheLineSize = 64;
const auto divisionByCacheLineSize = std::div(int64_t(size), int64_t(cacheLineSize));
size_type cacheLineBlocks = (size - 1) / cacheLineSize;
size_type cacheLineBlocks = size_type(divisionByCacheLineSize.quot);
const size_type supplement = divisionByCacheLineSize.rem ? 1 : 0;
cacheLineBlocks += supplement;
int exponent;
const double significand = std::frexp(cacheLineBlocks, &exponent);
const double factorOneDotFiveSignificant = std::ceil(significand * 4.) / 4.;
cacheLineBlocks = size_type(std::ldexp(factorOneDotFiveSignificant, exponent));
return cacheLineBlocks * cacheLineSize;
return (cacheLineBlocks + 1) * cacheLineSize;
}
size_type countOccurrence(SmallStringView text)
......
......@@ -1067,13 +1067,13 @@ TEST(SmallString, OptimalHeapCacheLineForSize)
ASSERT_THAT(SmallString::optimalHeapCapacity(191), 192);
ASSERT_THAT(SmallString::optimalHeapCapacity(193), 256);
ASSERT_THAT(SmallString::optimalHeapCapacity(255), 256);
ASSERT_THAT(SmallString::optimalHeapCapacity(257), 384);
ASSERT_THAT(SmallString::optimalHeapCapacity(257), 384);
ASSERT_THAT(SmallString::optimalHeapCapacity(256), 256);
ASSERT_THAT(SmallString::optimalHeapCapacity(257), 320);
ASSERT_THAT(SmallString::optimalHeapCapacity(383), 384);
ASSERT_THAT(SmallString::optimalHeapCapacity(385), 512);
ASSERT_THAT(SmallString::optimalHeapCapacity(385), 448);
ASSERT_THAT(SmallString::optimalHeapCapacity(4095), 4096);
ASSERT_THAT(SmallString::optimalHeapCapacity(4096), 4096);
ASSERT_THAT(SmallString::optimalHeapCapacity(4097), 6144);
ASSERT_THAT(SmallString::optimalHeapCapacity(4097), 4160);
}
TEST(SmallString, OptimalCapacityForSize)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment