Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add type hints #46

Merged
merged 2 commits into from
Jun 17, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Add type hints to speed up
The code loops through large byte arrays and checks the type every time.
Tested with Ara ETP that the type hints are indeed a good optimisation
in this case.
solita-antti-mottonen committed Jun 14, 2024
commit 27db3021904bd73157e413a71a74ff4d642f22e5
8 changes: 4 additions & 4 deletions src/clj/puumerkki/pdf.clj
Original file line number Diff line number Diff line change
@@ -72,15 +72,15 @@
(if (= pos len)
target
(do
(aset-byte target pos (aget arr (+ start pos)))
(aset-byte target pos (aget ^bytes arr (+ start pos)))
(recur (+ pos 1))))))))

(defn copy-bytes! [array content offset]
(if (>= (count array) (+ offset (count content)))
(loop [pos (- (count content) 1)]
(if (> pos -1)
(do
(aset-byte array (+ offset pos) (aget content pos))
(aset-byte array (+ offset pos) (aget ^bytes content pos))
(recur (- pos 1)))
array))
nil))
@@ -216,7 +216,7 @@
;; count number of ascii zeroes at position (which are used for signature area filling)
(defn zeroes-at [data pos]
(loop [pos pos n 0]
(let [val (aget data pos)]
(let [val (aget ^bytes data pos)]
(if (= val 48)
(recur (+ pos 1) (+ n 1))
n))))
@@ -226,7 +226,7 @@
(cond
(not (aget data pos))
false ;; out of data
(and (= (aget data pos) 60) (> (zeroes-at data (+ pos 1)) 512))
(and (= (aget ^bytes data pos) 60) (> (zeroes-at data (+ pos 1)) 512))
(+ pos 1)
:else
(recur (+ pos 1)))))