1
0
mirror of https://github.com/luanti-org/luanti.git synced 2025-10-13 16:45:20 +02:00

Reserve vectors before pushing and other code quality changes (#11161)

This commit is contained in:
sfan5
2021-04-05 13:38:31 +02:00
committed by GitHub
parent 3e1904fa8c
commit f0bad0e2ba
20 changed files with 106 additions and 108 deletions

View File

@@ -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());