Skip to content

Commit

Permalink
Make DECODE-LENGTH and ENCODE-LENGTH avaialble at compile time
Browse files Browse the repository at this point in the history
They are required to define limit constants later in the file.
  • Loading branch information
chaitanyagupta committed Nov 24, 2017
1 parent f13ea9a commit ba4e853
Showing 1 changed file with 14 additions and 13 deletions.
27 changes: 14 additions & 13 deletions qbase64.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -28,19 +28,20 @@
(deftype scheme ()
'(member :original :uri))

(declaim (ftype (function (positive-fixnum t) positive-fixnum) encode-length))
(defun encode-length (length encode-trailing-bytes)
(declare (type positive-fixnum length))
(declare (optimize speed))
(* 4 (if encode-trailing-bytes
(ceiling length 3)
(floor length 3))))

(declaim (ftype (function (positive-fixnum) positive-fixnum) decode-length))
(defun decode-length (length)
(declare (type positive-fixnum length))
(declare (optimize speed))
(* 3 (ceiling length 4)))
(eval-when (:compile-toplevel :load-toplevel :execute)
(declaim (ftype (function (positive-fixnum t) positive-fixnum) encode-length))
(defun encode-length (length encode-trailing-bytes)
(declare (type positive-fixnum length))
(declare (optimize speed))
(* 4 (if encode-trailing-bytes
(ceiling length 3)
(floor length 3))))

(declaim (ftype (function (positive-fixnum) positive-fixnum) decode-length))
(defun decode-length (length)
(declare (type positive-fixnum length))
(declare (optimize speed))
(* 3 (ceiling length 4))))

(define-constant +max-bytes-length+ (- (decode-length most-positive-fixnum) 3)
"Max length of the byte array that is used as encoding input or decoding output")
Expand Down

0 comments on commit ba4e853

Please sign in to comment.