summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMaxime Coste <mawww@kakoune.org>2025-06-27 16:30:54 +1000
committerMaxime Coste <mawww@kakoune.org>2025-06-27 16:30:54 +1000
commitbb98f2b439ad0b0d7b1116614cba7598f0cd8d44 (patch)
treec10401b8e1456d89347a28a0e1aa0d62730a9241
parentb3c3baef518d65f30a34b06764c6529b8247b837 (diff)
Remove <algorithm> include from string.hh
This was only used for std::min and std::equal, which can be replaced with custom code and memcmp, this removes a costly header from the often used string.hh and may improve compilation speed slightly
-rw-r--r--src/string.hh15
1 files changed, 8 insertions, 7 deletions
diff --git a/src/string.hh b/src/string.hh
index 3b8c9013..619971bd 100644
--- a/src/string.hh
+++ b/src/string.hh
@@ -1,14 +1,14 @@
#ifndef string_hh_INCLUDED
#define string_hh_INCLUDED
-#include <climits>
-#include <cstddef>
#include "memory.hh"
#include "hash.hh"
#include "units.hh"
#include "utf8.hh"
-#include <algorithm>
+#include <climits>
+#include <cstddef>
+#include <cstring>
namespace Kakoune
{
@@ -298,9 +298,10 @@ inline String String::no_copy(StringView str) { return {NoCopy{}, str}; }
template<typename Type, typename CharType>
inline StringView StringOps<Type, CharType>::substr(ByteCount from, ByteCount length) const
{
- const auto str_len = type().length();
- kak_assert(from >= 0 and from <= str_len);
- return StringView{type().data() + (int)from, std::min(str_len - from, length >= 0 ? length : str_len)};
+ const auto str_length = type().length();
+ const auto max_length = str_length - from;
+ kak_assert(from >= 0 and max_length >= 0);
+ return StringView{type().data() + (int)from, length >= 0 and length < max_length ? length : max_length};
}
template<typename Type, typename CharType>
@@ -352,7 +353,7 @@ inline String operator+(StringView lhs, StringView rhs)
inline bool operator==(const StringView& lhs, const StringView& rhs)
{
return lhs.length() == rhs.length() and
- std::equal(lhs.begin(), lhs.end(), rhs.begin());
+ (lhs.empty() or std::memcmp(lhs.begin(), rhs.begin(), (size_t)lhs.length()) == 0);
}
inline auto operator<=>(const StringView& lhs, const StringView& rhs)