Repository navigation
Implement missing Type 4 operators and speed up execution - #606
Merged
Merged
Conversation
…cate neg, exp, ln, ceiling and round had no Operator variant, so a Type 4 function using any of them failed to parse with InvalidNumber. They now parse and evaluate: neg keeps integers (an i32::MIN operand becomes a real), exp and ln return reals and reject undefined results, and ceiling and round keep the operand's type, with round taking halves toward positive infinity. log was the natural logarithm; it is now base 10. atan returned angles in (-180, 180]; they are now normalized into [0, 360). floor and truncate converted every result to an integer, which also made large reals such as 1e10 fail with an overflow; they now keep the operand's type, like ceiling and round. Fixes #591 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Each taken if/ifelse cloned the whole operand stack into the child frame and copied it back when the procedure finished. Procedures now run on the caller's stack: frames only track the operators and instruction pointer, and the stack lives in an OperandStack beside them. copy extends the stack from within instead of collecting a temporary Vec, and execute takes the input stack by value so the caller's Vec is reused instead of copied. A criterion bench (benches/calculator.rs) runs three programs over 256 samples each. Against the previous commit, median of five interleaved rounds with the release profile: nested ifelse 124.3 µs -> 82.0 µs (-34%) arithmetic 139.4 µs -> 119.7 µs (-14%) stack shuffling 156.2 µs -> 119.3 µs (-24%) 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 |
5 of 6 tasks
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
Type 4 operators (fixes #591)
neg,exp,ln,ceilingandround, which previously failed to parse withInvalidNumberand made the owning shading or color space fail to load.logis now base 10 (it computed the natural log).atanreturns angles in [0, 360) instead of (-180, 180].floorandtruncatekeep the operand's type, so1e10 floorno longer fails with an overflow.cviremains the real→integer conversion.Faster execution
if/ifelseprocedures run on the caller's operand stack instead of cloning it into each child frame and copying it back.copyusesextend_from_withininstead of a temporaryVec.executetakes the input stack by value, soPostScriptCalculatorFunction::interpolatehands over itsVecinstead of having it copied.New criterion bench
crates/pdf-postscript/benches/calculator.rs(256 samples per iteration). Median of 5 interleaved A/B rounds against the first commit, release profile:ifelseParsing allocations are left to #590.
Test plan
cargo test -p pdf-postscript -p pdf-functioncargo clippy -p pdf-postscript -p pdf-function --all-targets --all-features -- -D warnings,cargo fmt --check-2147483648 neg,-8 0.5 exp(error),100 log,-1 -1 atan(225),1e10 floor,±2.5 round🤖 Generated with Claude Code