From b0195bb4480bfabf2df3d5ace299534d84810718 Mon Sep 17 00:00:00 2001 From: John Benediktsson Date: Tue, 25 Feb 2014 10:04:08 -0800 Subject: [PATCH] io: minor cleanups. --- core/io/encodings/encodings.factor | 9 +++++---- core/io/streams/sequence/sequence.factor | 12 ++++++------ 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/core/io/encodings/encodings.factor b/core/io/encodings/encodings.factor index 6b33357dfb..9da1d6b03b 100644 --- a/core/io/encodings/encodings.factor +++ b/core/io/encodings/encodings.factor @@ -106,8 +106,7 @@ M: decoder stream-element-type : fix-cr ( decoder c -- c' ) over cr>> [ - over cr- - dup CHAR: \n eq? [ drop (read1) ] [ nip ] if + over cr- dup CHAR: \n eq? [ drop (read1) ] [ nip ] if ] [ nip ] if ; inline M: decoder stream-read1 ( decoder -- ch ) @@ -151,8 +150,9 @@ M: decoder stream-contents* : line-ends\r ( stream str -- str ) swap cr+ ; inline : line-ends\n ( stream str -- str ) - over cr>> over empty? and - [ drop dup cr- stream-readln ] [ swap cr- ] if ; inline + over cr>> [ + over cr- [ stream-readln ] [ nip ] if-empty + ] [ nip ] if ; inline : handle-readln ( stream str ch -- str ) { @@ -188,6 +188,7 @@ M: encoder dispose stream>> dispose ; inline M: encoder stream-flush stream>> stream-flush ; inline INSTANCE: encoder plain-writer + PRIVATE> GENERIC# re-encode 1 ( stream encoding -- newstream ) diff --git a/core/io/streams/sequence/sequence.factor b/core/io/streams/sequence/sequence.factor index bffceb24c9..10b5d39e8c 100644 --- a/core/io/streams/sequence/sequence.factor +++ b/core/io/streams/sequence/sequence.factor @@ -28,16 +28,16 @@ SLOT: i [ [ dup pick + ] change-i underlying>> ] bi [ (copy) drop ] 2curry keep ; inline -: check-byte-array ( buf -- buf ) - dup byte-array? [ "not a byte array" throw ] unless ; inline +: check-byte-array ( buf stream -- buf stream ) + over byte-array? [ "not a byte array" throw ] unless ; inline -: check-string ( buf -- buf ) - dup string? [ "not a string" throw ] unless ; inline +: check-string ( buf stream -- buf stream ) + over 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 ] dip ((sequence-read-unsafe)) ] - [ [ check-string ] dip ((sequence-read-unsafe)) ] if ; inline + [ check-byte-array ((sequence-read-unsafe)) ] + [ check-string ((sequence-read-unsafe)) ] if ; inline PRIVATE>