forked from qt-creator/qt-creator
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 <tobias.hunger@theqtcompany.com>
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user