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.
This commit is contained in:
Milian Wolff 2016-01-15 14:55:22 +01:00 committed by Stephen Kelly
parent bd2384f593
commit 70788e9264
1 changed files with 2 additions and 2 deletions

View File

@ -52,13 +52,13 @@ template<typename T, size_t N>
size_t cmArraySize(const T (&)[N]) { return N; }
template<typename T, size_t N>
bool cmHasLiteralPrefix(T str1, const char (&str2)[N])
bool cmHasLiteralPrefix(const T& str1, const char (&str2)[N])
{
return cmHasLiteralPrefixImpl(str1, str2, N - 1);
}
template<typename T, size_t N>
bool cmHasLiteralSuffix(T str1, const char (&str2)[N])
bool cmHasLiteralSuffix(const T& str1, const char (&str2)[N])
{
return cmHasLiteralSuffixImpl(str1, str2, N - 1);
}