mirror of
https://github.com/Icinga/icinga2.git
synced 2025-04-08 17:05:25 +02:00
String: Mark move constructor & assignment op as noexcept
The Icinga DB code performs intensive operations on certain STL containers, primarily on `std::vector<String>`. Specifically, it inserts 2-3 new elements at the beginning of a vector containing thousands of elements. Without this commit, all the existing elements would be unnecessarily copied just to accommodate the new elements at the front. By making this change, the compiler is able to optimize STL operations like `push_back`, `emplace_back`, and `insert`, enabling it to prefer the move constructor over copy operations, provided it is guaranteed that no exceptions will be thrown.
This commit is contained in:
parent
9a9c0a1fe0
commit
8236d74669
@ -33,7 +33,7 @@ String::String(const String& other)
|
||||
: m_Data(other)
|
||||
{ }
|
||||
|
||||
String::String(String&& other)
|
||||
String::String(String&& other) noexcept
|
||||
: m_Data(std::move(other.m_Data))
|
||||
{ }
|
||||
|
||||
@ -66,7 +66,7 @@ String& String::operator=(const String& rhs)
|
||||
return *this;
|
||||
}
|
||||
|
||||
String& String::operator=(String&& rhs)
|
||||
String& String::operator=(String&& rhs) noexcept
|
||||
{
|
||||
m_Data = std::move(rhs.m_Data);
|
||||
return *this;
|
||||
|
@ -44,7 +44,7 @@ public:
|
||||
String(std::string data);
|
||||
String(String::SizeType n, char c);
|
||||
String(const String& other);
|
||||
String(String&& other);
|
||||
String(String&& other) noexcept;
|
||||
|
||||
#ifndef _MSC_VER
|
||||
String(Value&& other);
|
||||
@ -56,7 +56,7 @@ public:
|
||||
{ }
|
||||
|
||||
String& operator=(const String& rhs);
|
||||
String& operator=(String&& rhs);
|
||||
String& operator=(String&& rhs) noexcept;
|
||||
String& operator=(Value&& rhs);
|
||||
String& operator=(const std::string& rhs);
|
||||
String& operator=(const char *rhs);
|
||||
|
Loading…
x
Reference in New Issue
Block a user