Skip to content

Commit

Permalink
Code clean up.
Browse files Browse the repository at this point in the history
  • Loading branch information
stassats committed Jun 7, 2011
1 parent 7fe2325 commit d18fea4
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 11 deletions.
23 changes: 14 additions & 9 deletions disk.lisp
Expand Up @@ -3,12 +3,13 @@
(in-package #:storage)

(eval-when (:compile-toplevel :load-toplevel :execute)
(defvar *codes* #(ascii-string
identifiable cons
string null symbol
storable-class
standard-object
fixnum bignum ratio)))
(defparameter *codes*
#(ascii-string
identifiable cons
string null symbol
storable-class
standard-object
fixnum bignum ratio)))

(declaim (type simple-vector *codes*))

Expand All @@ -25,7 +26,7 @@
(defun type-code (type)
(position type *codes*)))

(defvar *code-functions* (make-array (length *codes*)))
(defparameter *code-functions* (make-array (length *codes*)))
(declaim (type (simple-array function (*)) *code-functions*))

(defmacro defreader (type (stream) &body body)
Expand Down Expand Up @@ -63,6 +64,9 @@
(loop for char across string
always (char< char +ascii-char-limit+)))

(deftype storage-fixnum ()
`(signed-byte ,(* +fixnum-length+ 8)))

;;;

(defun slot-effective-definition (class slot-name)
Expand Down Expand Up @@ -154,13 +158,14 @@
(+ 1 ;; tag
1 ;; sign
(typecase object
(#.`(signed-byte ,(* +fixnum-length+ 8))
(storage-fixnum
+fixnum-length+)
(t (+ 1 ;; size
(* (ceiling (integer-length (abs object))
(* +fixnum-length+ 8)) +fixnum-length+))))))

(defun write-fixnum (n stream)
(declare (storage-fixnum n))
(write-n-bytes #.(type-code 'fixnum) 1 stream)
(write-n-bytes (if (minusp n) 1 0) 1 stream)
(write-n-bytes (abs n) +fixnum-length+ stream))
Expand All @@ -181,7 +186,7 @@

(defmethod write-object ((object integer) stream)
(typecase object
(#.`(signed-byte ,(* +fixnum-length+ 8))
(storage-fixnum
(write-fixnum object stream))
(t (write-bignum object stream))))

Expand Down
9 changes: 7 additions & 2 deletions io-sbcl.lisp
Expand Up @@ -56,6 +56,9 @@
(fixnum offset))
(mask-field (byte 24 0) (sb-sys:sap-ref-32 sap offset)))

(defun signal-end-of-file (stream)
(error "End of file ~a" stream))

(declaim (inline advance-stream))
(defun advance-stream (n stream)
(declare (optimize (space 0))
Expand All @@ -64,13 +67,15 @@
(new-position (sb-ext:truly-the word (+ sap n))))
(when (> new-position
(mmap-stream-end stream))
(error "End of file ~a" stream))
(signal-end-of-file stream))
(setf (mmap-stream-sap stream) new-position)
(sb-sys:int-sap sap)))

(declaim (inline read-n-bytes))
(defun read-n-bytes (n stream)
(declare (optimize (speed 3))
(declare (optimize speed)
#+sbcl
(sb-ext:muffle-conditions sb-ext:compiler-note)
(type (integer 1 4) n))
(funcall (ecase n
(1 #'sb-sys:sap-ref-8)
Expand Down

0 comments on commit d18fea4

Please sign in to comment.