Skip to content

Commit

Permalink
Merge pull request #15 from jbouwman/speed-decl
Browse files Browse the repository at this point in the history
drop most speed decls
  • Loading branch information
Jesse Bouwman authored Mar 24, 2024
2 parents c978112 + 9415030 commit 5dfe081
Show file tree
Hide file tree
Showing 16 changed files with 63 additions and 166 deletions.
6 changes: 3 additions & 3 deletions src/lib/char/encoding/encoding.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -202,9 +202,9 @@ a CHARACTER-ENCONDING object, it is returned unmodified."
;;; object.
(defmacro instantiate-concrete-mappings
(&key (encodings (hash-table-keys *abstract-mappings*))
(optimize '((speed 3) (debug 0) (compilation-speed 0)))
octet-seq-getter octet-seq-setter octet-seq-type
code-point-seq-getter code-point-seq-setter code-point-seq-type
(optimize '((speed 3) (debug 0) (compilation-speed 0)))
octet-seq-getter octet-seq-setter octet-seq-type
code-point-seq-getter code-point-seq-setter code-point-seq-type
(instantiate-decoders t))
`(let ((ht (make-hash-table :test 'eq)))
(declare (optimize ,@optimize)
Expand Down
13 changes: 4 additions & 9 deletions src/lib/char/string.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@ are less than UNICODE-CHAR-CODE-LIMIT."
(defun string-to-u8 (string &key (encoding *default-character-encoding*)
(start 0) end (use-bom :default)
(errorp (not *suppress-character-coding-errors*)))
(declare (optimize (speed 3) (safety 2)))
(let ((*suppress-character-coding-errors* (not errorp)))
(etypecase string
(simple-base-string
Expand Down Expand Up @@ -189,24 +188,20 @@ are less than UNICODE-CHAR-CODE-LIMIT."
vector-size-in-chars concatenate-strings-to-octets))

(defun standard-alpha-byte-p (byte)
(declare (type u8 byte)
(optimize (speed 3) (safety 0)))
(declare (type u8 byte))
(or (<= #.(char-code #\A) byte #.(char-code #\Z))
(<= #.(char-code #\a) byte #.(char-code #\z))))

(defun standard-alpha-char-p (char)
(declare (type character char)
(optimize (speed 3) (safety 0)))
(declare (type character char))
(standard-alpha-byte-p (char-code char)))

(defun standard-alphanumeric-p (char)
(declare (type character char)
(optimize (speed 3) (safety 0)))
(declare (type character char))
(or (digit-char-p char)
(standard-alpha-char-p char)))

(defun standard-alphanumeric-byte-p (byte)
(declare (type u8 byte)
(optimize (speed 3) (safety 0)))
(declare (type u8 byte))
(or (<= #.(char-code #\0) byte #.(char-code #\9))
(standard-alpha-byte-p byte)))
15 changes: 5 additions & 10 deletions src/lib/codec/base64.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,7 @@ WHITESPACE can be one of:
:signal - Signal a BAD-BASE64-CHARACTER condition using SIGNAL.
:error - Signal a BAD-BASE64-CHARACTER condition using ERROR."
hose sink)
(declare (optimize (speed 3) (safety 1))
(type decode-table table)
(declare (type decode-table table)
(type ,(ecase hose
(:stream 'stream)
(:string 'string))
Expand Down Expand Up @@ -308,8 +307,7 @@ WHITESPACE can be one of:

(defun round-next-multiple (x n)
"Round x up to the next highest multiple of n."
(declare (fixnum n)
(optimize (speed 3) (safety 1) (space 0)))
(declare (fixnum n))
(let ((remainder (mod x n)))
(declare (fixnum remainder))
(if (zerop remainder)
Expand All @@ -332,8 +330,7 @@ with a #\Newline."
'((string input)))
(:usb8-array
'((type (array u8 (*)) input))))
(fixnum columns)
(optimize (speed 3) (safety 1) (space 0)))
(fixnum columns))
(let ((pad (if uri *uri-pad-char* *pad-char*))
(encode-table (if uri *uri-encode-table* *encode-table*)))
(declare (simple-string encode-table)
Expand Down Expand Up @@ -489,8 +486,7 @@ with a #\Newline."
(defun integer-to-base64-string (input &key (uri nil) (columns 0))
"Encode an integer to base64 format."
(declare (integer input)
(fixnum columns)
(optimize (speed 3) (space 0) (safety 1)))
(fixnum columns))
(let ((pad (if uri *uri-pad-char* *pad-char*))
(encode-table (if uri *uri-encode-table* *encode-table*)))
(declare (simple-string encode-table)
Expand Down Expand Up @@ -548,8 +544,7 @@ with a #\Newline."
(defun integer-to-base64-stream (input stream &key (uri nil) (columns 0))
"Encode an integer to base64 format."
(declare (integer input)
(fixnum columns)
(optimize (speed 3) (space 0) (safety 1)))
(fixnum columns))
(let ((pad (if uri *uri-pad-char* *pad-char*))
(encode-table (if uri *uri-encode-table* *encode-table*)))
(declare (simple-string encode-table)
Expand Down
1 change: 0 additions & 1 deletion src/lib/codec/inflate.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,6 @@ the input and the number of bytes written to the output."
(decode-value (table state)
(declare (type huffman-decode-table table))
(declare (type inflate-state state))
(declare (optimize (speed 3)))
(ensure-bits (hdt-bits table) state)
(let ((bits (inflate-state-bits state)))
(declare (type u32 bits))
Expand Down
9 changes: 0 additions & 9 deletions src/lib/function.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ PLACES contains a function."
functions in turn to its arguments, returning the primary value of the first
predicate that returns true, without calling the remaining predicates.
If none of the predicates returns true, NIL is returned."
(declare (optimize (speed 3) (safety 1) (debug 1)))
(let ((predicate (ensure-function predicate))
(more-predicates (mapcar #'ensure-function more-predicates)))
(lambda (&rest arguments)
Expand Down Expand Up @@ -74,7 +73,6 @@ predicates returns false, returns the primary value of the last predicate."
"Returns a function composed of FUNCTION and MORE-FUNCTIONS that applies its
arguments to to each in turn, starting from the rightmost of MORE-FUNCTIONS,
and then calling the next one with the primary value of the last."
(declare (optimize (speed 3) (safety 1) (debug 1)))
(reduce (lambda (f g)
(let ((f (ensure-function f))
(g (ensure-function g)))
Expand All @@ -93,7 +91,6 @@ and then calling the next one with the primary value of the last."
(funs (make-gensym-list (length args) "COMPOSE")))
`(let ,(loop for f in funs for arg in args
collect `(,f (ensure-function ,arg)))
(declare (optimize (speed 3) (safety 1) (debug 1)))
(lambda (&rest arguments)
(declare (dynamic-extent arguments))
,(compose-1 funs))))))
Expand All @@ -103,7 +100,6 @@ and then calling the next one with the primary value of the last."
its arguments to each in turn, starting from the rightmost of
MORE-FUNCTIONS, and then calling the next one with all the return values of
the last."
(declare (optimize (speed 3) (safety 1) (debug 1)))
(reduce (lambda (f g)
(let ((f (ensure-function f))
(g (ensure-function g)))
Expand All @@ -121,7 +117,6 @@ the last."
(let* ((args (cons function more-functions))
(funs (make-gensym-list (length args) "MV-COMPOSE")))
`(let ,(mapcar #'list funs args)
(declare (optimize (speed 3) (safety 1) (debug 1)))
(lambda (&rest arguments)
(declare (dynamic-extent arguments))
,(compose-1 funs))))))
Expand All @@ -131,7 +126,6 @@ the last."
(defun curry (function &rest arguments)
"Returns a function that applies ARGUMENTS and the arguments
it is called with to FUNCTION."
(declare (optimize (speed 3) (safety 1)))
(let ((fn (ensure-function function)))
(lambda (&rest more)
(declare (dynamic-extent more))
Expand All @@ -143,15 +137,13 @@ it is called with to FUNCTION."
(fun (gensym "FUN")))
`(let ((,fun (ensure-function ,function))
,@(mapcar #'list curries arguments))
(declare (optimize (speed 3) (safety 1)))
(lambda (&rest more)
(declare (dynamic-extent more))
(apply ,fun ,@curries more)))))

(defun rcurry (function &rest arguments)
"Returns a function that applies the arguments it is called
with and ARGUMENTS to FUNCTION."
(declare (optimize (speed 3) (safety 1)))
(let ((fn (ensure-function function)))
(lambda (&rest more)
(declare (dynamic-extent more))
Expand All @@ -162,7 +154,6 @@ with and ARGUMENTS to FUNCTION."
(fun (gensym "FUN")))
`(let ((,fun (ensure-function ,function))
,@(mapcar #'list rcurries arguments))
(declare (optimize (speed 3) (safety 1)))
(lambda (&rest more)
(declare (dynamic-extent more))
(multiple-value-call ,fun (values-list more) ,@rcurries)))))
Expand Down
1 change: 0 additions & 1 deletion src/lib/list.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,6 @@ expected-type designator of a TYPE-ERROR."
in the list designated by KEYS and values corresponding to them are removed.
The returned property-list may share structure with the PLIST, but PLIST is
not destructively modified. Keys are compared using EQ."
(declare (optimize (speed 3)))
;; FIXME: possible optimization: (remove-from-plist '(:x 0 :a 1 :b 2) :a)
;; could return the tail without consing up a new list.
(loop for (key . rest) on plist by #'cddr
Expand Down
6 changes: 2 additions & 4 deletions src/lib/seq/vector.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@
split-vector-from-start split-vector-from-end))

(defun split-vector-from-end (position-fn vector start end count remove-empty-subseqs)
(declare (optimize (speed 3) (debug 0))
(type (function (vector fixnum) (or null fixnum)) position-fn))
(declare (type (function (vector fixnum) (or null fixnum)) position-fn))
(loop
:with end = (or end (length vector))
:for right := end :then left
Expand All @@ -30,8 +29,7 @@
:finally (return (values (nreverse subseqs) (1+ left)))))

(defun split-vector-from-start (position-fn vector start end count remove-empty-subseqs)
(declare (optimize (speed 3) (debug 0))
(type vector vector)
(declare (type vector vector)
(type (function (vector fixnum) (or null fixnum)) position-fn))
(let ((length (length vector)))
(loop
Expand Down
6 changes: 2 additions & 4 deletions src/lib/stream.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -502,8 +502,7 @@ READ-BYTE."
(let* ((pos (input-buffer-pos buffer))
(vec (input-buffer-vector buffer))
(vec-len (length vec)))
(declare (optimize (speed 3) (safety 1))
(type ->u8 vec)
(declare (type ->u8 vec)
(type fixnum pos vec-len new-pos))
;; Only need to update if pos or new-pos is in stream range.
(when-let ((stream-update-needed? (or (> pos vec-len)
Expand Down Expand Up @@ -570,8 +569,7 @@ READ-BYTE."

(defun fast-write-byte (byte output-buffer)
(declare (type u8 byte)
(type output-buffer output-buffer)
(optimize (speed 3) (safety 1)))
(type output-buffer output-buffer))
(when (= (output-buffer-fill output-buffer)
(array-dimension (output-buffer-vector output-buffer) 0))
(if (streamp (output-buffer-output output-buffer))
Expand Down
Loading

0 comments on commit 5dfe081

Please sign in to comment.