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 <christian.kandeler@qt.io>
This commit is contained in:
Tim Blechmann
2021-04-25 10:47:19 +08:00
parent c4c3d4cc33
commit f4a64fd8c8
2 changed files with 6 additions and 2 deletions

View File

@@ -109,6 +109,10 @@ public:
: m_src(src)
{}
PPToken(QByteArray &&src)
: m_src(std::move(src))
{}
void setSource(const QByteArray &src)
{ m_src = src; }

View File

@@ -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)) {