From f4a64fd8c8492effc27a4609f1f5bccdba742a92 Mon Sep 17 00:00:00 2001 From: Tim Blechmann Date: Sun, 25 Apr 2021 10:47:19 +0800 Subject: [PATCH] cplusplus: `PPToken` - introduce move constructor profiling qt-creator on my codebase i saw quite a few instances where reference counting of `QByteArray` showed up in `Preprocessor::handleFunctionLikeMacro` (hundreds of milliseconds of CPU time when profiling for a few seconds). using move semantics we can avoid this source of reference counting. Change-Id: I19a88a0501064f53d8095f7377bf901e462d25a0 Reviewed-by: Christian Kandeler --- src/libs/cplusplus/PPToken.h | 4 ++++ src/libs/cplusplus/pp-engine.cpp | 4 ++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/libs/cplusplus/PPToken.h b/src/libs/cplusplus/PPToken.h index af31dec861c..a2d0f2af532 100644 --- a/src/libs/cplusplus/PPToken.h +++ b/src/libs/cplusplus/PPToken.h @@ -109,6 +109,10 @@ public: : m_src(src) {} + PPToken(QByteArray &&src) + : m_src(std::move(src)) + {} + void setSource(const QByteArray &src) { m_src = src; } diff --git a/src/libs/cplusplus/pp-engine.cpp b/src/libs/cplusplus/pp-engine.cpp index 913a6a3c9b6..b3cfe6bd15a 100644 --- a/src/libs/cplusplus/pp-engine.cpp +++ b/src/libs/cplusplus/pp-engine.cpp @@ -1219,12 +1219,12 @@ bool Preprocessor::handleFunctionLikeMacro(const Macro *macro, // No formal macro parameter for this identifier in the body. bodyTk.f.generated = true; bodyTk.lineno = baseLine; - expanded.push_back(bodyTk); + expanded.push_back(std::move(bodyTk)); } } else if (bodyTk.isNot(T_POUND) && bodyTk.isNot(T_POUND_POUND)) { bodyTk.f.generated = true; bodyTk.lineno = baseLine; - expanded.push_back(bodyTk); + expanded.push_back(std::move(bodyTk)); } if (i > 1 && body[int(i) - 1].is(T_POUND_POUND)) {