diff --git a/src/libs/utils/smallstringlayout.h b/src/libs/utils/smallstringlayout.h index 4ec5a07898e..dd9cf7a817a 100644 --- a/src/libs/utils/smallstringlayout.h +++ b/src/libs/utils/smallstringlayout.h @@ -134,6 +134,12 @@ struct ReferenceLayout template struct ShortStringLayout { + constexpr ShortStringLayout() noexcept = default; + constexpr ShortStringLayout( + typename ControlBlock::SizeType shortStringSize) noexcept + : control(shortStringSize, false, false) + {} + ControlBlock control; char string[MaximumShortStringDataAreaSize]; }; @@ -154,27 +160,18 @@ struct StringDataLayout { constexpr StringDataLayout(const char *string, size_type size) noexcept : reference(string, size, 0) - { - } + {} - template = 0> + template constexpr StringDataLayout(const char (&string)[Size]) noexcept - : shortString(ShortStringLayout{}) - { - for (size_type i = 0; i < Size; ++i) - shortString.string[i] = string[i]; - - shortString.control.setShortStringSize(Size - 1); - shortString.control.setIsShortString(true); - shortString.control.setIsReadOnlyReference(false); - } - - template = 1> - constexpr StringDataLayout(const char(&string)[Size]) noexcept - : reference(string, Size - 1, 0) { + if constexpr (Size <= MaximumShortStringDataAreaSize) { + shortString = {Size - 1}; + for (size_type i = 0; i < Size; ++i) + shortString.string[i] = string[i]; + } else { + reference = {string, Size - 1, 0}; + } } constexpr static