[flexi-streams-cvs] r29 - in branches/edi: . doc test

eweitz at common-lisp.net eweitz at common-lisp.net
Sun May 18 14:59:45 UTC 2008


Author: eweitz
Date: Sun May 18 10:59:44 2008
New Revision: 29

Modified:
   branches/edi/doc/index.html
   branches/edi/specials.lisp
   branches/edi/strings.lisp
   branches/edi/test/test.lisp
Log:
Some optimization


Modified: branches/edi/doc/index.html
==============================================================================
--- branches/edi/doc/index.html	(original)
+++ branches/edi/doc/index.html	Sun May 18 10:59:44 2008
@@ -977,8 +977,8 @@
 Converts the Lisp string <code><i>string</i></code> from <code><i>start</i></code> to <code><i>end</i></code> to an array of
 <a href="#octet">octets</a> corresponding to the <a href="#external-formats">external format</a> <code><i>external-format</i></code>. The defaults for
 <code><i>start</i></code> and <code><i>end</i></code>
-are <code>0</code> and <code>NIL</code> (meaning the length of the
-vector).  The default for <code><i>external-format</i></code> is the
+are <code>0</code> and the length of the
+string.  The default for <code><i>external-format</i></code> is the
 value of
 evaluating <code>(<a
 href="#make-external-format">MAKE-EXTERNAL-FORMAT</a> :LATIN1)</code>
@@ -986,15 +986,15 @@
 </blockquote>
 
 <p><br>[Function]
-<br><a class=none name="octets-to-string"><b>octets-to-string</b> <i>vector <tt>&key</tt> external-format start end</i> => <i>string</i></a>
+<br><a class=none name="octets-to-string"><b>octets-to-string</b> <i>sequence <tt>&key</tt> external-format start end</i> => <i>string</i></a>
 
-<blockquote><br> Converts the Lisp vector <code><i>vector</i></code>
+<blockquote><br> Converts the Lisp sequence <code><i>sequence</i></code>
 of <a href="#octet">octets</a> from <code><i>start</i></code>
 to <code><i>end</i></code> to string using
 the <a href="#external-formats">external
 format</a> <code><i>external-format</i></code>.  The defaults for
 <code><i>start</i></code> and <code><i>end</i></code>
-are <code>0</code> and the length of the vector.  The default
+are <code>0</code> and the length of the sequence.  The default
 for <code><i>external-format</i></code> is the value of
 evaluating <code>(<a
 href="#make-external-format">MAKE-EXTERNAL-FORMAT</a> :LATIN1)</code>
@@ -1037,7 +1037,7 @@
 numerous patches and additions.
 
 <p>
-$Header: /usr/local/cvsrep/flexi-streams/doc/index.html,v 1.98 2007/12/29 23:15:27 edi Exp $
+$Header: /usr/local/cvsrep/flexi-streams/doc/index.html,v 1.100 2008/05/18 14:59:02 edi Exp $
 <p><a href="http://weitz.de/index.html">BACK TO MY HOMEPAGE</a>
 
 </body>

Modified: branches/edi/specials.lisp
==============================================================================
--- branches/edi/specials.lisp	(original)
+++ branches/edi/specials.lisp	Sun May 18 10:59:44 2008
@@ -1,5 +1,5 @@
 ;;; -*- Mode: LISP; Syntax: COMMON-LISP; Package: FLEXI-STREAMS; Base: 10 -*-
-;;; $Header: /usr/local/cvsrep/flexi-streams/specials.lisp,v 1.27 2008/05/18 01:21:34 edi Exp $
+;;; $Header: /usr/local/cvsrep/flexi-streams/specials.lisp,v 1.28 2008/05/18 14:59:00 edi Exp $
 
 ;;; Copyright (c) 2005-2008, Dr. Edmund Weitz.  All rights reserved.
 
@@ -29,6 +29,15 @@
 
 (in-package :flexi-streams)
 
+(defvar *standard-optimize-settings*
+  '(optimize
+    speed
+    (safety 0)
+    (space 0)
+    (debug 1)
+    (compilation-speed 0))
+  "The standard optimize settings used by most declaration expressions.")
+
 (deftype octet ()
   "A shortcut for \(UNSIGNED-BYTE 8)."
   '(unsigned-byte 8))

Modified: branches/edi/strings.lisp
==============================================================================
--- branches/edi/strings.lisp	(original)
+++ branches/edi/strings.lisp	Sun May 18 10:59:44 2008
@@ -1,5 +1,5 @@
 ;;; -*- Mode: LISP; Syntax: COMMON-LISP; Package: FLEXI-STREAMS; Base: 10 -*-
-;;; $Header: /usr/local/cvsrep/flexi-streams/strings.lisp,v 1.9 2008/05/18 13:59:13 edi Exp $
+;;; $Header: /usr/local/cvsrep/flexi-streams/strings.lisp,v 1.10 2008/05/18 14:59:00 edi Exp $
 
 ;;; Copyright (c) 2005-2008, Dr. Edmund Weitz.  All rights reserved.
 
@@ -34,6 +34,8 @@
                                 (start 0) (end (length string)))
   "Converts the Lisp string STRING from START to END to an array of
 octets corresponding to the external format EXTERNAL-FORMAT."
+  (declare #.*standard-optimize-settings*)
+  (declare (fixnum start end) (string string))
   (setq external-format (maybe-convert-external-format external-format))
   (let ((factor (encoding-factor external-format))
         (length (- end start)))    
@@ -45,7 +47,7 @@
                                  :adjustable t)))
          (flet ((writer (octet)
                   (vector-push-extend octet octets)))
-           (loop for i from start below end
+           (loop for i of-type fixnum from start below end
                  do (char-to-octets external-format
                                     (char string i)
                                     #'writer
@@ -55,33 +57,58 @@
        (let ((octets (make-array (* factor length)
                                  :element-type 'octet))
              (j 0))
+         (declare (fixnum j))
          (flet ((writer (octet)
-                  (setf (aref octets j) octet)
+                  (setf #+:lispworks (sys:typed-aref '(unsigned-byte 8) octets j)
+                        #-:lispworks (aref octets j)
+                        octet)
                   (incf j)))
-           (loop for i from start below end do
+           (loop for i of-type fixnum from start below end do
                  (char-to-octets external-format
                                  (char string i)
                                  #'writer
                                  nil)))
          octets)))))
 
-(defun octets-to-string (vector &key
-                                (external-format (make-external-format :latin1))
-                                (start 0) (end (length vector)))
-  "Converts the Lisp vector VECTOR of octets from START to END to
+(defun octets-to-string (sequence &key
+                                  (external-format (make-external-format :latin1))
+                                  (start 0) (end (length sequence)))
+  "Converts the Lisp sequence SEQUENCE of octets from START to END to
 string using the external format EXTERNAL-FORMAT."
+  (declare #.*standard-optimize-settings*)
+  (declare (fixnum start end))
   (setq external-format (maybe-convert-external-format external-format))
-  (let ((factor (encoding-factor external-format))
-        (length (- end start))
-        (i start))
-    (labels ((reader ()
-               (when (>= i end)
-                 ;; TODO...
-                 (error "End of data."))
-               (prog1
-                   (aref vector i)
-                 (incf i)))
-             (pseudo-writer (octet)
+  (let* ((factor (encoding-factor external-format))
+         (length (- end start))
+         (i start)
+         (reader (etypecase sequence
+                   #+:lispworks
+                   ((array octet *)
+                    (lambda ()
+                      (when (>= i end)
+                        ;; TODO...
+                        (error "End of data."))
+                      (prog1
+                          (sys:typed-aref '(unsigned-byte 8) sequence i)
+                        (incf i))))
+                   ((array * *)
+                    (lambda ()
+                      (when (>= i end)
+                        ;; TODO...
+                        (error "End of data."))
+                      (prog1
+                          (aref sequence i)
+                        (incf i))))
+                   (list
+                    (lambda ()
+                      (when (>= i end)
+                        ;; TODO...
+                        (error "End of data."))
+                      (prog1
+                          (nth i sequence)
+                        (incf i)))))))
+    (declare (fixnum i))
+    (labels ((pseudo-writer (octet)
                (declare (ignore octet))
                (decf i))
              (unreader (char)
@@ -92,7 +119,7 @@
              (next-char ()
                (code-char
                 (octets-to-char-code external-format
-                                     #'reader
+                                     reader
                                      #'unreader
                                      nil))))
       (etypecase factor
@@ -108,6 +135,7 @@
          (let* ((string-length (/ length factor))
                 (string (make-array string-length
                                     :element-type 'char*)))
-           (loop for j from 0 below string-length
-                 do (setf (char string j) (next-char))
+           (declare (fixnum string-length))
+           (loop for j of-type fixnum from 0 below string-length
+                 do (setf (schar string j) (next-char))
                  finally (return string))))))))

Modified: branches/edi/test/test.lisp
==============================================================================
--- branches/edi/test/test.lisp	(original)
+++ branches/edi/test/test.lisp	Sun May 18 10:59:44 2008
@@ -1,5 +1,5 @@
 ;;; -*- Mode: LISP; Syntax: COMMON-LISP; Package: FLEXI-STREAMS-TEST; Base: 10 -*-
-;;; $Header: /usr/local/cvsrep/flexi-streams/test/test.lisp,v 1.21 2008/05/18 01:21:36 edi Exp $
+;;; $Header: /usr/local/cvsrep/flexi-streams/test/test.lisp,v 1.22 2008/05/18 14:59:04 edi Exp $
 
 ;;; Copyright (c) 2006-2008, Dr. Edmund Weitz.  All rights reserved.
 
@@ -263,10 +263,12 @@
 that the stream conversion functions work."
   (let* ((full-path (merge-pathnames pathspec *this-file*))
          (octets-vector (file-as-octet-vector full-path))
+         (octets-list (coerce octets-vector 'list))
          (string (file-as-string full-path external-format)))
     (with-test ((format nil "String tests with format ~S."
                         (flex::normalize-external-format external-format)))
       (check (string= (octets-to-string octets-vector :external-format external-format) string))
+      (check (string= (octets-to-string octets-list :external-format external-format) string))
       (check (equalp (string-to-octets string :external-format external-format) octets-vector)))))
 
 (defmacro using-values ((&rest values) &body body)



More information about the Flexi-streams-cvs mailing list