pdf: dedupe num/deref helpers into objects
- Commit
013b1780e4233f9a7999c45a1bbebee4eaa58358- Author
- Vayun Mathur <[email protected]>
- When
- 2026-12-01 21:00 UTC (4 days ago)
- Parents
fc30ba2
filters.rs and type3.rs each carried private copies of num and deref
that were byte-identical (modulo visibility) to the pub(crate)
canonical pair already in objects.rs. Delete both private copies
(14 lines each) and import the canonical helpers with
use crate::objects::{deref, num}; in each file, so there is a single
definition to maintain. All call sites keep using the unqualified
names, so behaviour is unchanged.
Verified: bodies compared verbatim before deleting - identical.
cargo test -p pdf_render --locked: 676 passed, 0 failed (baseline).
cargo fmt --all -- --check: clean. structure_check lines: OK,
pdf module 75,809 lines (delta -25: +2 imports, -27 duplicate lines).Diff
pdf/src/main/rust/src/filters.rs
diff --git a/pdf/src/main/rust/src/filters.rs b/pdf/src/main/rust/src/filters.rsindex 4ab584130a..6ab8828fb5 100644--- a/pdf/src/main/rust/src/filters.rs+++ b/pdf/src/main/rust/src/filters.rs@@ -2,6 +2,7 @@ //! Implements chain decoding with case-insensitive filter normalization. //! Used to close P0 blank-page blockers: ASCIIHex/85, LZW, Flate, RunLength, CCITT, JBIG2. +use crate::objects::{deref, num}; use lopdf::{Dictionary, Document, Object}; #[derive(Clone, Debug, PartialEq, Eq)]@@ -46,20 +47,6 @@ impl Default for CcittParams { } } -fn num(obj: &Object) -> Option<f64> {- match obj {- Object::Integer(i) => Some(*i as f64),- Object::Real(r) => Some(*r as f64),- _ => None,- }-}-fn deref<'a>(doc: &'a Document, obj: &'a Object) -> Option<&'a Object> {- match doc.dereference(obj) {- Ok((_, o)) => Some(o),- Err(_) => None,- }-}- pub fn normalize_filter_name(name: &str) -> FilterKind { let n = name.trim().trim_start_matches('/').to_ascii_lowercase(); match n.as_str() {
pdf/src/main/rust/src/type3.rs
diff --git a/pdf/src/main/rust/src/type3.rs b/pdf/src/main/rust/src/type3.rsindex ddb72b18c2..8039ba74ca 100644--- a/pdf/src/main/rust/src/type3.rs+++ b/pdf/src/main/rust/src/type3.rs@@ -2,24 +2,12 @@ //! Minimal parser for FontMatrix, CharProcs, Encoding. //! Full CharProcs interpretation deferred to shading-style rasterization. +use crate::objects::{deref, num}; use lopdf::{Dictionary, Document, Object, ObjectId}; use std::collections::HashMap; type Mat = [f64; 6]; -fn num(obj: &Object) -> Option<f64> {- match obj {- Object::Integer(i) => Some(*i as f64),- Object::Real(r) => Some(*r as f64),- _ => None,- }-}-fn deref<'a>(doc: &'a Document, obj: &'a Object) -> Option<&'a Object> {- match doc.dereference(obj) {- Ok((_, o)) => Some(o),- Err(_) => None,- }-} fn read_matrix_from_array(arr: &[Object], doc: &Document) -> Option<Mat> { let nums: Vec<f64> = arr.iter().filter_map(|o| deref(doc, o).and_then(num).or_else(|| num(o))).collect();