2
1
mirror of https://github.com/qpdf/qpdf.git synced 2024-09-16 15:19:07 +00:00

Refactor Pl_QPDFTokenizer::finish

Remove unnecessary use of shared pointers and avoid unnecessary string
creation.
This commit is contained in:
m-holger 2024-07-27 18:55:43 +01:00
parent 986a253cdd
commit 1536a76071
2 changed files with 5 additions and 8 deletions

View File

@ -36,20 +36,17 @@ void
Pl_QPDFTokenizer::finish()
{
m->buf.finish();
auto input = std::shared_ptr<InputSource>(
// line-break
new BufferInputSource("tokenizer data", m->buf.getBuffer(), true));
auto input = BufferInputSource("tokenizer data", m->buf.getBuffer(), true);
std::string empty;
while (true) {
QPDFTokenizer::Token token =
m->tokenizer.readToken(input, "offset " + std::to_string(input->tell()), true);
auto token = m->tokenizer.readToken(input, empty, true);
m->filter->handleToken(token);
if (token.getType() == QPDFTokenizer::tt_eof) {
break;
} else if (token.isWord("ID")) {
// Read the space after the ID.
char ch = ' ';
input->read(&ch, 1);
input.read(&ch, 1);
m->filter->handleToken(
// line-break
QPDFTokenizer::Token(QPDFTokenizer::tt_space, std::string(1, ch)));

View File

@ -904,7 +904,7 @@ QPDFTokenizer::readToken(
throw QPDFExc(
qpdf_e_damaged_pdf,
input.getName(),
context,
context.empty() ? "offset " + std::to_string(input.getLastOffset()) : context,
input.getLastOffset(),
token.getErrorMessage());
}