anchor.diff:              (enc-bom-encoding enc)
               #()))))
   
  -;;; FIXME: we shouldn't really need that coercion to UNICODE-STRING
  -;;; but we kind of because it's declared all over.  To avoid that,
  -;;; we'd need different types for input and output strings.  Or maybe
  -;;; this is not a problem; figure that out.
   (defun string-to-octets (string &key (encoding *default-character-encoding*)
                            (start 0) end (use-bom :default)
                            (errorp (not *suppress-character-coding-errors*)))
  -  (check-type string string)
  -  (with-checked-simple-vector ((string (coerce string 'unicode-string))
  -                               (start start) (end end))
  -    (declare (type simple-unicode-string string))
  -    (let* ((*suppress-character-coding-errors* (not errorp))
  -           (mapping (lookup-string-vector-mapping encoding))
  -           (bom (bom-vector encoding use-bom))
  -           (vector (make-array (the array-index
  -                                 (+ (funcall (octet-counter mapping)
  -                                             string start end -1)
  -                                    (length bom)))
  -                               :element-type '(unsigned-byte 8))))
  -      (replace vector bom)
  -      (funcall (encoder mapping) string start end vector (length bom))
  -      vector)))
  +  (declare (optimize (speed 3) (safety 2)))
  +  (let ((*suppress-character-coding-errors* (not errorp)))
  +    (etypecase string
  +      (simple-base-string
  +       (unless end
  +         (setf end (length string)))
  +       (check-vector-bounds string start end)
  +       (let* ((mapping (lookup-mapping *simple-base-string-vector-mappings*
  +                                       encoding))
  +              (bom (bom-vector encoding use-bom))
  +              (bom-length (length bom))
  +              (result (make-array (+ (length string) bom-length)
  +                                  :element-type '(unsigned-byte 8))))
  +         (replace result bom)
  +         (funcall (the function (encoder mapping))
  +                  string start end result bom-length)
  +         result))
  +      (string
  +       ;; FIXME: we shouldn't really need that coercion to UNICODE-STRING
  +       ;; but we kind of because it's declared all over.  To avoid that,
  +       ;; we'd need different types for input and output strings.  Or maybe
  +       ;; this is not a problem; figure that out.
  +       (with-checked-simple-vector ((string (coerce string 'unicode-string))
  +                                    (start start) (end end))
  +         (declare (type simple-unicode-string string))
  +         (let* ((mapping (lookup-mapping *string-vector-mappings* encoding))
  +                (bom (bom-vector encoding use-bom))
  +                (bom-length (length bom))
  +                (result (make-array (+ (the array-index
  +                                         (funcall (the function (octet-counter mapping))
  +                                                  string start end -1))
  +                                       bom-length)
  +                                    :element-type '(unsigned-byte 8))))
  +           (replace result bom)
  +           (funcall (the function (encoder mapping))
  +                    string start end result bom-length)
  +           result))))))
   
   (defun concatenate-strings-to-octets (encoding &rest strings)
     "Optimized equivalent of
  
positive.code:    :code-point-seq-getter string-get
     :code-point-seq-type simple-unicode-string))
  
  (defun lookup-string-vector-mapping (encoding)
    (lookup-mapping *string-vector-mappings* encoding))
  
  ;;; debugging stuff, TODO: refactor
  
  
negative.code:   (with-checked-simple-vector ((vector vector) (start start) (end end))
      (declare (type (simple-array (unsigned-byte 8) (*)) vector))
      (let ((*suppress-character-coding-errors* (not errorp))
            (mapping (lookup-mapping *string-vector-mappings* encoding)))
        (multiple-value-bind (size new-end)
            (funcall (code-point-counter mapping) vector start end -1)
          ;; TODO we could optimize ASCII here: the result should
  