2
1
mirror of https://github.com/qpdf/qpdf.git synced 2024-11-09 14:50:58 +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() Pl_QPDFTokenizer::finish()
{ {
m->buf.finish(); m->buf.finish();
auto input = std::shared_ptr<InputSource>( auto input = BufferInputSource("tokenizer data", m->buf.getBuffer(), true);
// line-break std::string empty;
new BufferInputSource("tokenizer data", m->buf.getBuffer(), true));
while (true) { while (true) {
QPDFTokenizer::Token token = auto token = m->tokenizer.readToken(input, empty, true);
m->tokenizer.readToken(input, "offset " + std::to_string(input->tell()), true);
m->filter->handleToken(token); m->filter->handleToken(token);
if (token.getType() == QPDFTokenizer::tt_eof) { if (token.getType() == QPDFTokenizer::tt_eof) {
break; break;
} else if (token.isWord("ID")) { } else if (token.isWord("ID")) {
// Read the space after the ID. // Read the space after the ID.
char ch = ' '; char ch = ' ';
input->read(&ch, 1); input.read(&ch, 1);
m->filter->handleToken( m->filter->handleToken(
// line-break // line-break
QPDFTokenizer::Token(QPDFTokenizer::tt_space, std::string(1, ch))); QPDFTokenizer::Token(QPDFTokenizer::tt_space, std::string(1, ch)));

View File

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