From bb98f2b439ad0b0d7b1116614cba7598f0cd8d44 Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Fri, 27 Jun 2025 16:30:54 +1000 Subject: Remove 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 --- src/string.hh | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) (limited to 'src') 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 -#include #include "memory.hh" #include "hash.hh" #include "units.hh" #include "utf8.hh" -#include +#include +#include +#include namespace Kakoune { @@ -298,9 +298,10 @@ inline String String::no_copy(StringView str) { return {NoCopy{}, str}; } template inline StringView StringOps::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 @@ -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) -- cgit v1.2.3