From dcb91bac19ea518a68a3981ef85b629661c65750 Mon Sep 17 00:00:00 2001 From: Madeline Busig Date: Thu, 21 Mar 2024 20:35:22 -0600 Subject: [PATCH] Optimize string single character append Now uses a specialized implementation instead of the append multiple characters implementation. Useful for appending single characters to string streams (ex. newline). --- src/string.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/string.cpp b/src/string.cpp index 6fb47aa..d1ba8ae 100644 --- a/src/string.cpp +++ b/src/string.cpp @@ -255,7 +255,12 @@ istring& istring::operator+=(const string_view& str) { } istring& istring::operator+=(char ch) { - return append(1, ch); + if (m_size < m_capacity) { + m_str[m_size] = ch; + ++m_size; + } + + return *this; } istring& istring::replace(size_t pos, size_t count, const string_view& str) {