diff -rN -u old-sbcl/src/code/ansi-stream.lisp new-sbcl/src/code/ansi-stream.lisp
--- old-sbcl/src/code/ansi-stream.lisp	2007-11-22 14:46:20.000000000 +0100
+++ new-sbcl/src/code/ansi-stream.lisp	2007-11-22 14:46:23.000000000 +0100
@@ -84,7 +84,7 @@
 ;;; file, and when processing other files which use ANSI-STREAM.
 ;;; -- WHN 2000-12-13
 (eval-when (:compile-toplevel :load-toplevel :execute)
-  (defconstant +ansi-stream-in-buffer-length+ 512))
+  (defconstant +ansi-stream-in-buffer-length+ 4096))
 
 (deftype ansi-stream-in-buffer ()
   `(simple-array (unsigned-byte 8) (,+ansi-stream-in-buffer-length+)))
diff -rN -u old-sbcl/src/code/fd-stream.lisp new-sbcl/src/code/fd-stream.lisp
--- old-sbcl/src/code/fd-stream.lisp	2007-11-22 14:46:20.000000000 +0100
+++ new-sbcl/src/code/fd-stream.lisp	2007-11-22 14:46:22.000000000 +0100
@@ -1077,7 +1077,7 @@
       (when (member external-format (first entry))
         (return-from pick-input-routine
           (values (symbol-function (third entry))
-                  'character
+                  type
                   1
                   (symbol-function (second entry))
                   (first (first entry)))))))
@@ -2333,7 +2333,7 @@
 (defun open (filename
              &key
              (direction :input)
-             (element-type 'base-char)
+             (element-type 'character)
              (if-exists nil if-exists-given)
              (if-does-not-exist nil if-does-not-exist-given)
              (external-format :default)
diff -rN -u old-sbcl/src/code/stream.lisp new-sbcl/src/code/stream.lisp
--- old-sbcl/src/code/stream.lisp	2007-11-22 14:46:20.000000000 +0100
+++ new-sbcl/src/code/stream.lisp	2007-11-22 14:46:22.000000000 +0100
@@ -240,51 +240,56 @@
 #!-sb-fluid (declaim (inline ansi-stream-read-line))
 (defun ansi-stream-read-line (stream eof-error-p eof-value recursive-p)
   (declare (ignore recursive-p))
-  (prepare-for-fast-read-char stream
-    ;; Check whether the FAST-READ-CHAR buffer contains a newline. If it
-    ;; does, we can do things quickly by just copying the line from the
-    ;; buffer instead of doing repeated calls to FAST-READ-CHAR.
-    (when %frc-buffer%
-      (locally
-          ;; For %FIND-POSITION transform
-          (declare (optimize (speed 2)))
-        (let ((pos (position #\Newline %frc-buffer%
-                             :test #'char=
-                             :start %frc-index%)))
-          (when pos
-            (let* ((len (- pos %frc-index%))
-                   (res (make-string len)))
-              (replace res %frc-buffer% :start2 %frc-index% :end2 pos)
-              (setf %frc-index% (1+ pos))
-              (done-with-fast-read-char)
-              (return-from ansi-stream-read-line res))))))
-    (let ((res (make-string 80))
-          (len 80)
-          (index 0))
-      (loop
-         (let ((ch (fast-read-char nil nil)))
-           (cond (ch
-                  (when (char= ch #\newline)
+  (macrolet ((make-result-string (&optional (length 80))
+               `(ecase (ansi-stream-element-type stream)
+                  (character (make-string ,length :element-type 'character))
+                  (base-char (make-string ,length :element-type 'base-char)))))
+    (prepare-for-fast-read-char stream
+      ;; Check whether the FAST-READ-CHAR buffer contains a newline. If it
+      ;; does, we can do things quickly by just copying the line from the
+      ;; buffer instead of doing repeated calls to FAST-READ-CHAR.
+      (when %frc-buffer%
+        (locally
+            ;; For %FIND-POSITION transform
+            (declare (optimize (speed 2)))
+          (let ((pos (position #\Newline %frc-buffer%
+                               :test #'char=
+                               :start %frc-index%)))
+            (when pos
+              (let* ((len (- pos %frc-index%))
+                     (res (make-result-string len)))
+                (replace res %frc-buffer% :start2 %frc-index% :end2 pos)
+                (setf %frc-index% (1+ pos))
+                (done-with-fast-read-char)
+                (return-from ansi-stream-read-line res))))))
+      (let* ((res (make-result-string))
+             (len 80)
+             (index 0))
+        (declare (type index len index))
+        (loop
+           (let ((ch (fast-read-char nil nil)))
+             (cond (ch
+                    (when (char= ch #\newline)
+                      (done-with-fast-read-char)
+                      (return (values (%shrink-vector res index) nil)))
+                    (when (= index len)
+                      (setq len (* len 2))
+                      (let ((new (make-result-string len)))
+                        (replace new res)
+                        (setq res new)))
+                    (setf (schar res index) ch)
+                    (incf index))
+                   ((zerop index)
+                    (done-with-fast-read-char)
+                    (return (values (eof-or-lose stream
+                                                 eof-error-p
+                                                 eof-value)
+                                    t)))
+                   ;; Since FAST-READ-CHAR already hit the eof char, we
+                   ;; shouldn't do another READ-CHAR.
+                   (t
                     (done-with-fast-read-char)
-                    (return (values (%shrink-vector res index) nil)))
-                  (when (= index len)
-                    (setq len (* len 2))
-                    (let ((new (make-string len)))
-                      (replace new res)
-                      (setq res new)))
-                  (setf (schar res index) ch)
-                  (incf index))
-                 ((zerop index)
-                  (done-with-fast-read-char)
-                  (return (values (eof-or-lose stream
-                                               eof-error-p
-                                               eof-value)
-                                  t)))
-                 ;; Since FAST-READ-CHAR already hit the eof char, we
-                 ;; shouldn't do another READ-CHAR.
-                 (t
-                  (done-with-fast-read-char)
-                  (return (values (%shrink-vector res index) t)))))))))
+                    (return (values (%shrink-vector res index) t))))))))))
 
 (defun read-line (&optional (stream *standard-input*) (eof-error-p t) eof-value
                             recursive-p)
diff -rN -u old-sbcl/src/code/string.lisp new-sbcl/src/code/string.lisp
--- old-sbcl/src/code/string.lisp	2007-11-22 14:46:20.000000000 +0100
+++ new-sbcl/src/code/string.lisp	2007-11-22 14:46:23.000000000 +0100
@@ -415,7 +415,9 @@
     (do ((index start (1+ index)))
         ((or (= index (the fixnum end))
              (not (find (schar string index) char-bag :test #'char=)))
-         (subseq (the simple-string string) index end))
+         (if (zerop index)
+             string
+             (subseq (the simple-string string) index end)))
       (declare (fixnum index)))))
 
 (defun string-right-trim (char-bag string)
@@ -423,7 +425,9 @@
     (do ((index (1- (the fixnum end)) (1- index)))
         ((or (< index start)
              (not (find (schar string index) char-bag :test #'char=)))
-         (subseq (the simple-string string) start (1+ index)))
+         (if (= end (1+ index))
+             string
+             (subseq (the simple-string string) start (1+ index))))
       (declare (fixnum index)))))
 
 (defun string-trim (char-bag string)
@@ -442,4 +446,7 @@
                                           :test #'char=)))
                            (1+ index))
                         (declare (fixnum index)))))
-      (subseq (the simple-string string) left-end right-end))))
+      (if (and (zerop left-end)
+               (= end right-end))
+          string
+          (subseq (the simple-string string) left-end right-end)))))

