From 80f88318a66aee44df1b741da35ea89fce7a8db2 Mon Sep 17 00:00:00 2001 From: John Benediktsson Date: Mon, 10 Mar 2014 19:56:42 -0700 Subject: [PATCH] io.streams.sequence: support slices (fix io.streams.peek test failure). --- core/io/streams/sequence/sequence.factor | 31 ++++++++++++++---------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/core/io/streams/sequence/sequence.factor b/core/io/streams/sequence/sequence.factor index f85cc13b99..4df422843a 100644 --- a/core/io/streams/sequence/sequence.factor +++ b/core/io/streams/sequence/sequence.factor @@ -20,24 +20,29 @@ SLOT: i : (sequence-read-length) ( n buf stream -- buf count ) [ underlying>> length ] [ i>> ] bi - rot min ; inline -: ( dst n i src -- n copy ) - [ 0 ] 3curry dip ; inline +: ( dst n src-i src dst-i -- n copy ) + [ ] curry 3curry dip ; inline -: ((sequence-read-unsafe)) ( n buf stream -- count ) - [ (sequence-read-length) ] - [ [ dup pick + ] change-i underlying>> ] bi - [ (copy) drop ] 2curry keep ; inline +: ((sequence-read-unsafe)) ( n buf stream offset -- count ) + [ + [ (sequence-read-length) ] + [ [ dup pick + ] change-i underlying>> ] bi + ] dip [ (copy) drop ] 3curry keep ; inline -: check-byte-array ( buf stream -- buf stream ) - over byte-array? [ "not a byte array" throw ] unless ; inline +: check-byte-array ( buf stream offset -- buf stream offset ) + pick byte-array? [ "not a byte array" throw ] unless ; inline -: check-string ( buf stream -- buf stream ) - over string? [ "not a string" throw ] unless ; inline +: check-string ( buf stream offset -- buf stream offset ) + pick string? [ "not a string" throw ] unless ; inline : (sequence-read-unsafe) ( n buf stream -- count ) - [ integer>fixnum ] 2dip dup stream-element-type +byte+ eq? - [ check-byte-array ((sequence-read-unsafe)) ] - [ check-string ((sequence-read-unsafe)) ] if ; inline + [ integer>fixnum ] + [ dup slice? [ [ seq>> ] [ from>> ] bi ] [ 0 ] if ] + [ + swap over stream-element-type +byte+ eq? + [ check-byte-array ((sequence-read-unsafe)) ] + [ check-string ((sequence-read-unsafe)) ] if + ] tri* ; inline PRIVATE>