2
1
mirror of https://github.com/qpdf/qpdf.git synced 2024-12-22 02:49:00 +00:00

Avoid unnecessary string copies in ContentNormalizer::handleToken

This commit is contained in:
m-holger 2024-07-27 16:26:19 +01:00
parent fa9df75bd4
commit 959ae4b4da
2 changed files with 7 additions and 7 deletions

View File

@ -11,7 +11,6 @@ ContentNormalizer::ContentNormalizer() :
void
ContentNormalizer::handleToken(QPDFTokenizer::Token const& token)
{
std::string value = token.getRawValue();
QPDFTokenizer::token_type_e token_type = token.getType();
if (token_type == QPDFTokenizer::tt_bad) {
@ -24,6 +23,7 @@ ContentNormalizer::handleToken(QPDFTokenizer::Token const& token)
switch (token_type) {
case QPDFTokenizer::tt_space:
{
std::string const& value = token.getRawValue();
size_t len = value.length();
for (size_t i = 0; i < len; ++i) {
char ch = value.at(i);
@ -38,7 +38,7 @@ ContentNormalizer::handleToken(QPDFTokenizer::Token const& token)
}
}
}
break;
return;
case QPDFTokenizer::tt_string:
// Replacing string and name tokens in this way normalizes their representation as this will
@ -52,12 +52,12 @@ ContentNormalizer::handleToken(QPDFTokenizer::Token const& token)
default:
writeToken(token);
break;
return;
}
value = token.getRawValue();
if (((token_type == QPDFTokenizer::tt_string) || (token_type == QPDFTokenizer::tt_name)) &&
((value.find('\r') != std::string::npos) || (value.find('\n') != std::string::npos))) {
// tt_string or tt_name
std::string const& value = token.getRawValue();
if (value.find('\r') != std::string::npos || value.find('\n') != std::string::npos) {
write("\n");
}
}

View File

@ -148,7 +148,7 @@ QPDFObjectHandle::TokenFilter::write(std::string const& str)
void
QPDFObjectHandle::TokenFilter::writeToken(QPDFTokenizer::Token const& token)
{
std::string value = token.getRawValue();
std::string const& value = token.getRawValue();
write(value.c_str(), value.length());
}