mirror of
https://github.com/qpdf/qpdf.git
synced 2024-12-22 10:58:58 +00:00
Avoid unnecessary string copies in ContentNormalizer::handleToken
This commit is contained in:
parent
fa9df75bd4
commit
959ae4b4da
@ -11,7 +11,6 @@ ContentNormalizer::ContentNormalizer() :
|
|||||||
void
|
void
|
||||||
ContentNormalizer::handleToken(QPDFTokenizer::Token const& token)
|
ContentNormalizer::handleToken(QPDFTokenizer::Token const& token)
|
||||||
{
|
{
|
||||||
std::string value = token.getRawValue();
|
|
||||||
QPDFTokenizer::token_type_e token_type = token.getType();
|
QPDFTokenizer::token_type_e token_type = token.getType();
|
||||||
|
|
||||||
if (token_type == QPDFTokenizer::tt_bad) {
|
if (token_type == QPDFTokenizer::tt_bad) {
|
||||||
@ -24,6 +23,7 @@ ContentNormalizer::handleToken(QPDFTokenizer::Token const& token)
|
|||||||
switch (token_type) {
|
switch (token_type) {
|
||||||
case QPDFTokenizer::tt_space:
|
case QPDFTokenizer::tt_space:
|
||||||
{
|
{
|
||||||
|
std::string const& value = token.getRawValue();
|
||||||
size_t len = value.length();
|
size_t len = value.length();
|
||||||
for (size_t i = 0; i < len; ++i) {
|
for (size_t i = 0; i < len; ++i) {
|
||||||
char ch = value.at(i);
|
char ch = value.at(i);
|
||||||
@ -38,7 +38,7 @@ ContentNormalizer::handleToken(QPDFTokenizer::Token const& token)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
return;
|
||||||
|
|
||||||
case QPDFTokenizer::tt_string:
|
case QPDFTokenizer::tt_string:
|
||||||
// Replacing string and name tokens in this way normalizes their representation as this will
|
// 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:
|
default:
|
||||||
writeToken(token);
|
writeToken(token);
|
||||||
break;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
value = token.getRawValue();
|
// tt_string or tt_name
|
||||||
if (((token_type == QPDFTokenizer::tt_string) || (token_type == QPDFTokenizer::tt_name)) &&
|
std::string const& value = token.getRawValue();
|
||||||
((value.find('\r') != std::string::npos) || (value.find('\n') != std::string::npos))) {
|
if (value.find('\r') != std::string::npos || value.find('\n') != std::string::npos) {
|
||||||
write("\n");
|
write("\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -148,7 +148,7 @@ QPDFObjectHandle::TokenFilter::write(std::string const& str)
|
|||||||
void
|
void
|
||||||
QPDFObjectHandle::TokenFilter::writeToken(QPDFTokenizer::Token const& token)
|
QPDFObjectHandle::TokenFilter::writeToken(QPDFTokenizer::Token const& token)
|
||||||
{
|
{
|
||||||
std::string value = token.getRawValue();
|
std::string const& value = token.getRawValue();
|
||||||
write(value.c_str(), value.length());
|
write(value.c_str(), value.length());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user