diff options
author | sfan5 <sfan5@live.de> | 2021-04-05 13:38:31 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-04-05 13:38:31 +0200 |
commit | f0bad0e2badbb7d4777aac7de1b50239bca4010a (patch) | |
tree | 4c3115a42ac86e9a64d9e5f088fe187022885779 /src/util/enriched_string.cpp | |
parent | 3e1904fa8c4aae3448d58b7e60545a4fdd8234f3 (diff) | |
download | minetest-f0bad0e2badbb7d4777aac7de1b50239bca4010a.tar.gz minetest-f0bad0e2badbb7d4777aac7de1b50239bca4010a.tar.bz2 minetest-f0bad0e2badbb7d4777aac7de1b50239bca4010a.zip |
Reserve vectors before pushing and other code quality changes (#11161)
Diffstat (limited to 'src/util/enriched_string.cpp')
-rw-r--r-- | src/util/enriched_string.cpp | 10 |
1 files changed, 3 insertions, 7 deletions
diff --git a/src/util/enriched_string.cpp b/src/util/enriched_string.cpp index 762d094eb..b1f95215e 100644 --- a/src/util/enriched_string.cpp +++ b/src/util/enriched_string.cpp @@ -65,12 +65,14 @@ void EnrichedString::operator=(const wchar_t *str) addAtEnd(translate_string(std::wstring(str)), m_default_color); } -void EnrichedString::addAtEnd(const std::wstring &s, const SColor &initial_color) +void EnrichedString::addAtEnd(const std::wstring &s, SColor initial_color) { SColor color(initial_color); bool use_default = (m_default_length == m_string.size() && color == m_default_color); + m_colors.reserve(m_colors.size() + s.size()); + size_t i = 0; while (i < s.length()) { if (s[i] != L'\x1b') { @@ -200,12 +202,6 @@ const std::wstring &EnrichedString::getString() const return m_string; } -void EnrichedString::setDefaultColor(const irr::video::SColor &color) -{ - m_default_color = color; - updateDefaultColor(); -} - void EnrichedString::updateDefaultColor() { sanity_check(m_default_length <= m_colors.size()); |