Utils: Use [[likely]] and [[unlikely]]

Change-Id: I82cd1873c57c01cf39796e624e97dc9f0fdfbf0f
Reviewed-by: Thomas Hartmann <thomas.hartmann@qt.io>
This commit is contained in:
Marco Bubke
2025-02-27 15:27:28 +01:00
parent 56f02830cd
commit 3e1049e536

View File

@@ -112,13 +112,13 @@ public:
~BasicSmallString() noexcept
{
if (Q_UNLIKELY(hasAllocatedMemory()))
if (hasAllocatedMemory()) [[unlikely]]
Memory::deallocate(m_data.data());
}
BasicSmallString(const BasicSmallString &other) noexcept
{
if (Q_LIKELY(other.isShortString() || other.isReadOnlyReference()))
if (other.isShortString() || other.isReadOnlyReference()) [[likely]]
m_data = other.m_data;
else
new (this) BasicSmallString{other.data(), other.size()};
@@ -126,10 +126,10 @@ public:
BasicSmallString &operator=(const BasicSmallString &other) noexcept
{
if (Q_LIKELY(this != &other)) {
if (this != &other) [[likely]] {
this->~BasicSmallString();
if (Q_LIKELY(other.isShortString() || other.isReadOnlyReference()))
if (other.isShortString() || other.isReadOnlyReference()) [[likely]]
m_data = other.m_data;
else
new (this) BasicSmallString{other.data(), other.size()};
@@ -146,7 +146,7 @@ public:
BasicSmallString &operator=(BasicSmallString &&other) noexcept
{
if (Q_LIKELY(this != &other)) {
if (this != &other) [[likely]] {
this->~BasicSmallString();
m_data = std::move(other.m_data);
@@ -202,7 +202,7 @@ public:
void reserve(size_type newCapacity) noexcept
{
if (fitsNotInCapacity(newCapacity)) {
if (Q_UNLIKELY(hasAllocatedMemory())) {
if (hasAllocatedMemory()) {
m_data.setPointer(Memory::reallocate(m_data.data(), newCapacity));
m_data.setAllocatedCapacity(newCapacity);
} else {