From 038ad97a7c9ec919da118f2dc07f68562cc9a7be Mon Sep 17 00:00:00 2001 From: Hans Goudey Date: Fri, 2 Feb 2024 17:48:52 +0100 Subject: [PATCH] BLI: Avoid computing size when referencing std::string The std::string already knows its size; there's no need to find it from scratch. Pull Request: https://projects.blender.org/blender/blender/pulls/117757 --- source/blender/blenlib/BLI_string_ref.hh | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/source/blender/blenlib/BLI_string_ref.hh b/source/blender/blenlib/BLI_string_ref.hh index 2254796e902..c2ce0711516 100644 --- a/source/blender/blenlib/BLI_string_ref.hh +++ b/source/blender/blenlib/BLI_string_ref.hh @@ -449,7 +449,10 @@ inline StringRefNull::StringRefNull(const char *str) : StringRefBase(str, int64_ * Reference a std::string. Remember that when the std::string is destructed, the StringRefNull * will point to uninitialized memory. */ -inline StringRefNull::StringRefNull(const std::string &str) : StringRefNull(str.c_str()) {} +inline StringRefNull::StringRefNull(const std::string &str) + : StringRefNull(str.c_str(), int64_t(str.size())) +{ +} /** * Get the char at the given index.