]> gitweb.factorcode.org Git - factor.git/blobdiff - core/io/streams/sequence/sequence.factor
classes: use check-instance in a few places, to remove duplication.
[factor.git] / core / io / streams / sequence / sequence.factor
index 5a6a1618ca3d3f621613f38de63bd5c6992aec07..461df22cd90b43c20148c91851d2908d824353a2 100644 (file)
@@ -1,8 +1,8 @@
 ! Copyright (C) 2009 Daniel Ehrenberg
 ! See http://factorcode.org/license.txt for BSD license.
-USING: accessors byte-arrays combinators destructors growable
-io io.private io.streams.plain kernel math math.order sequences
-sequences.private strings ;
+USING: accessors byte-arrays classes combinators destructors
+growable io io.private io.streams.plain kernel math math.order
+sequences sequences.private strings ;
 IN: io.streams.sequence
 
 ! Readers
@@ -29,21 +29,13 @@ SLOT: i
         [ [ dup pick + ] change-i underlying>> ] bi
     ] dip [ <sequence-copy> (copy) drop ] 3curry keep ; inline
 
-ERROR: not-a-byte-array obj ;
-: check-byte-array ( buf stream offset -- buf stream offset )
-    pick byte-array? [ pick not-a-byte-array ] unless ; inline
-
-ERROR: not-a-string obj ;
-: check-string ( buf stream offset -- buf stream offset )
-    pick string? [ pick not-a-string ] unless ; inline
-
 : (sequence-read-unsafe) ( n buf stream -- count )
     [ integer>fixnum ]
     [ dup slice? [ [ seq>> ] [ from>> ] bi ] [ 0 ] if ]
     [
         tuck stream-element-type +byte+ eq?
-        [ check-byte-array sequence-copy-unsafe ]
-        [ check-string sequence-copy-unsafe ] if
+        [ [ byte-array check-instance ] 2dip sequence-copy-unsafe ]
+        [ [ string check-instance ] 2dip sequence-copy-unsafe ] if
     ] tri* ; inline
 
 PRIVATE>