From e562af2c299a7770f429df0161a2088622acf06c Mon Sep 17 00:00:00 2001 From: Marco Bubke Date: Mon, 22 Feb 2016 11:58:34 +0100 Subject: [PATCH] Utils: Rename isReference to isReadOnlyReference There is implicit knowledge that the reference is read only in the code so we should honor that and make is explicit. Change-Id: I0d6eab6595ae1414ad2607760a2e02fd49bafd72 Reviewed-by: Tobias Hunger --- src/libs/utils/smallstring.h | 12 ++++++------ src/libs/utils/smallstringlayout.h | 10 +++++----- src/libs/utils/smallstringliteral.h | 4 ++-- tests/unit/unittest/smallstringtest.cpp | 18 +++++++++--------- 4 files changed, 22 insertions(+), 22 deletions(-) diff --git a/src/libs/utils/smallstring.h b/src/libs/utils/smallstring.h index 75de4d660e..970496483a 100644 --- a/src/libs/utils/smallstring.h +++ b/src/libs/utils/smallstring.h @@ -96,7 +96,7 @@ public: m_data.shortString.string[size] = 0; m_data.shortString.shortStringSize = uchar(size); m_data.shortString.hasAllocated = false; - m_data.shortString.isReference = false; + m_data.shortString.isReadOnlyReference = false; } else { m_data.allocated.data.pointer = Memory::allocate(capacity + 1); std::memcpy(m_data.allocated.data.pointer, string, size); @@ -105,7 +105,7 @@ public: m_data.allocated.data.capacity = capacity; m_data.allocated.shortStringSize = 0; m_data.allocated.hasAllocated = true; - m_data.allocated.isReference = false; + m_data.allocated.isReadOnlyReference = false; } } @@ -130,7 +130,7 @@ public: #else SmallString(const SmallString &string) { - if (string.isShortString() || string.isReference()) + if (string.isShortString() || string.isReadOnlyReference()) m_data = string.m_data; else new (this) SmallString{string.data(), string.size()}; @@ -473,14 +473,14 @@ UNIT_TEST_PUBLIC: return !m_data.shortString.hasAllocated; } - bool isReference() const noexcept + bool isReadOnlyReference() const noexcept { - return m_data.shortString.isReference; + return m_data.shortString.isReadOnlyReference; } bool hasAllocatedMemory() const noexcept { - return !isShortString() && !isReference(); + return !isShortString() && !isReadOnlyReference(); } bool fitsNotInCapacity(size_type capacity) const noexcept diff --git a/src/libs/utils/smallstringlayout.h b/src/libs/utils/smallstringlayout.h index f5bd1415d9..0229e32b06 100644 --- a/src/libs/utils/smallstringlayout.h +++ b/src/libs/utils/smallstringlayout.h @@ -62,7 +62,7 @@ struct AllocatedLayout { } data; char dummy[maximumShortStringDataAreaSize - sizeof(Data)]; std::uint8_t shortStringSize: 6; - std::uint8_t isReference : 1; + std::uint8_t isReadOnlyReference : 1; std::uint8_t hasAllocated : 1; }; @@ -74,14 +74,14 @@ struct ReferenceLayout { } data; char dummy[maximumShortStringDataAreaSize - sizeof(Data)]; std::uint8_t shortStringSize: 6; - std::uint8_t isReference : 1; + std::uint8_t isReadOnlyReference : 1; std::uint8_t hasAllocated : 1; }; struct ShortStringLayout { char string[maximumShortStringDataAreaSize]; std::uint8_t shortStringSize: 6; - std::uint8_t isReference : 1; + std::uint8_t isReadOnlyReference : 1; std::uint8_t hasAllocated : 1; }; @@ -112,14 +112,14 @@ struct ALIGNAS_16 StringDataLayout { #pragma GCC diagnostic pop #endif shortString.hasAllocated = false; - shortString.isReference = false; + shortString.isReadOnlyReference = false; } else { reference.data.pointer = string; reference.data.size = Size - 1; reference.data.capacity = 0; reference.shortStringSize = 0; reference.hasAllocated = true; - reference.isReference = true; + reference.isReadOnlyReference = true; } #endif } diff --git a/src/libs/utils/smallstringliteral.h b/src/libs/utils/smallstringliteral.h index 315c64d07a..6ad79fe616 100644 --- a/src/libs/utils/smallstringliteral.h +++ b/src/libs/utils/smallstringliteral.h @@ -111,9 +111,9 @@ public: } constexpr - bool isReference() const noexcept + bool isReadOnlyReference() const noexcept { - return m_data.shortString.isReference; + return m_data.shortString.isReadOnlyReference; } operator SmallStringView() const diff --git a/tests/unit/unittest/smallstringtest.cpp b/tests/unit/unittest/smallstringtest.cpp index 5045ef89bb..b0d465e162 100644 --- a/tests/unit/unittest/smallstringtest.cpp +++ b/tests/unit/unittest/smallstringtest.cpp @@ -65,7 +65,7 @@ TEST(SmallString, ShortSmallStringLiteralIsShortSmallString) #if __cpp_constexpr >= 201304 ASSERT_TRUE(shortText.isShortString()); #else - ASSERT_TRUE(shortText.isReference()); + ASSERT_TRUE(shortText.isReadOnlyReference()); #endif } @@ -76,7 +76,7 @@ TEST(SmallString, ShortSmallStringIsShortSmallString) #if __cpp_constexpr >= 201304 ASSERT_TRUE(shortText.isShortString()); #else - ASSERT_TRUE(shortText.isReference()); + ASSERT_TRUE(shortText.isReadOnlyReference()); #endif } @@ -84,7 +84,7 @@ TEST(SmallString, ShortSmallStringIsReference) { SmallString longText("very very very very very long text"); - ASSERT_TRUE(longText.isReference()); + ASSERT_TRUE(longText.isReadOnlyReference()); } TEST(SmallString, ShortSmallStringIsNotReference) @@ -92,7 +92,7 @@ TEST(SmallString, ShortSmallStringIsNotReference) const char *shortCSmallString = "short string"; auto shortText = SmallString::fromUtf8(shortCSmallString); - ASSERT_FALSE(shortText.isReference()); + ASSERT_FALSE(shortText.isReadOnlyReference()); } TEST(SmallString, MaximumShortSmallString) @@ -106,7 +106,7 @@ TEST(SmallString, LongConstExpressionSmallStringIsReference) { SmallString longText("very very very very very very very very very very very long string"); - ASSERT_TRUE(longText.isReference()); + ASSERT_TRUE(longText.isReadOnlyReference()); } TEST(SmallString, CloneShortSmallString) @@ -145,7 +145,7 @@ TEST(SmallString, CopyShortConstExpressionSmallStringIsShortSmallString) #if __cpp_constexpr >= 201304 ASSERT_TRUE(shortTextCopy.isShortString()); #else - ASSERT_TRUE(shortTextCopy.isReference()); + ASSERT_TRUE(shortTextCopy.isReadOnlyReference()); #endif } @@ -164,7 +164,7 @@ TEST(SmallString, SmallStringFromCharacterArrayIsReference) SmallString longString(longCString); - ASSERT_TRUE(longString.isReference()); + ASSERT_TRUE(longString.isReadOnlyReference()); } TEST(SmallString, SmallStringFromCharacterPointerIsNotReference) @@ -173,7 +173,7 @@ TEST(SmallString, SmallStringFromCharacterPointerIsNotReference) SmallString longString = SmallString::fromUtf8(longCString); - ASSERT_FALSE(longString.isReference()); + ASSERT_FALSE(longString.isReadOnlyReference()); } TEST(SmallString, CopyStringFromReference) @@ -183,7 +183,7 @@ TEST(SmallString, CopyStringFromReference) longTextCopy = longText; - ASSERT_TRUE(longTextCopy.isReference()); + ASSERT_TRUE(longTextCopy.isReadOnlyReference()); } TEST(SmallString, SmallStringLiteralShortSmallStringDataAccess) -- GitLab