From 70788e92641c4cf4c3f20af607cc6e203203b420 Mon Sep 17 00:00:00 2001 From: Milian Wolff Date: Fri, 15 Jan 2016 14:55:22 +0100 Subject: [PATCH] Remove temporary allocations when calling cmHasLiteral{Suf,Pre}fix. When the first argument passed is a std::string, we need to take it by const&, otherwise we copy the string and trigger a temporary allocation. This patch removes a few 10k temporary allocations when running the CMake daemon on the KDevelop build dir. This hotspot was found with heaptrack. --- Source/cmAlgorithms.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Source/cmAlgorithms.h b/Source/cmAlgorithms.h index ef607d212..54617f30f 100644 --- a/Source/cmAlgorithms.h +++ b/Source/cmAlgorithms.h @@ -52,13 +52,13 @@ template size_t cmArraySize(const T (&)[N]) { return N; } template -bool cmHasLiteralPrefix(T str1, const char (&str2)[N]) +bool cmHasLiteralPrefix(const T& str1, const char (&str2)[N]) { return cmHasLiteralPrefixImpl(str1, str2, N - 1); } template -bool cmHasLiteralSuffix(T str1, const char (&str2)[N]) +bool cmHasLiteralSuffix(const T& str1, const char (&str2)[N]) { return cmHasLiteralSuffixImpl(str1, str2, N - 1); }