Repository navigation
Read content-stream operators through PdfOperatorVariant instead of PdfOperator - #587
Merged
Merged
Conversation
…dfOperator The PdfOperator trait was a closed trait used only to fill the operation-map dispatch table. Its NAME constant was never read and repeated the table's literals, the SC/sc operators needed placeholder types with unreachable call bodies, and inline images needed an always-failing read plus a parse-hook field. PdfOperatorVariant::read now matches the operator name and operand count in one place and calls each operator's inherent read, which returns the finished operator. Zero-operand operators become fieldless variants dispatched directly in PdfOperatorVariant::call. The stream parser handles BI itself. Recovery behaviour is unchanged. Dispatch no longer goes through a function pointer, which speeds up dispatch-heavy operator parsing by about 17%. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Conformance readsDocuments that Safe-PDF reads differently from the base commit, compared with PDFium. A read pdf.js corpus1009 documents compared with Improvements
840 documents of the PDFium corpus read as on Details are in the job summaries of the workflow run. Rerun a case locally with |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Removes the
PdfOperatortrait. Operators are now read through a singlePdfOperatorVariant::read(name, operands)match.The trait was closed and only used to fill the
operation_mapdispatch table:NAMEwas never read. It repeated the table's literals, which is howFended up unmapped.SC/scneeded placeholder types whosecallcould never run.BIneeded areadthat always failed, plus a parse-hook field used by no other operator.Changes
PdfOperatorVariant::readmatches(name, operand count)in one place. A wrong operand count is dropped exactly as before.readthat returnsSelfand acallmethod.q,Q,BT,S,f,W, …) become fieldless variants dispatched directly inPdfOperatorVariant::call. Their four files are removed.SC/scread throughread_without_patternon the two color structs.BIitself. Recovery behaviour is unchanged.operator_trait.rsandoperation_map.rs.About 1,320 lines removed and 670 added.
Performance
operator_parsing, median of 5 interleaved runs against agit archiveexport ofmain, shipped release profile:Testing
cargo test,cargo clippy --all --workspace,cargo fmt --check, and a wasm check ofweb-canvas-example.pdf-graphics-skiaandpdf-conformance, because their Skia build needs a download the local sandbox blocks. CI covers them.🤖 Generated with Claude Code