From 82f2daa6ad66f75a7495c92fe7c297c07722845c Mon Sep 17 00:00:00 2001 From: John Benediktsson Date: Wed, 25 Jul 2012 20:55:01 -0700 Subject: [PATCH] io: more inlining. --- core/io/io.factor | 23 ++++++++++++++--------- core/io/streams/c/c.factor | 2 +- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/core/io/io.factor b/core/io/io.factor index 67377dd2c2..20d3b491b3 100644 --- a/core/io/io.factor +++ b/core/io/io.factor @@ -29,7 +29,8 @@ GENERIC: stream-seek ( n seek-type stream -- ) GENERIC: stream-seekable? ( stream -- ? ) GENERIC: stream-length ( stream -- n/f ) -: stream-print ( str stream -- ) [ stream-write ] [ stream-nl ] bi ; +: stream-print ( str stream -- ) + [ stream-write ] [ stream-nl ] bi ; inline ! Default streams MIXIN: input-stream @@ -158,7 +159,9 @@ ERROR: invalid-read-buffer buf stream ; input-stream get swap each-stream-line ; inline : stream-lines ( stream -- seq ) - [ [ ] collector [ each-stream-line ] dip { } like ] with-disposal ; + [ + [ ] collector [ each-stream-line ] dip { } like + ] with-disposal ; inline : lines ( -- seq ) input-stream get stream-lines ; inline @@ -183,21 +186,24 @@ CONSTANT: each-block-size 65536 dup rot [ [ (new-sequence-for-stream) ] [ [ stream-read-unsafe ] curry keep resize ] bi - ] with-disposal ; + ] with-disposal ; inline + : (stream-contents-by-block) ( stream -- seq ) [ [ [ ] collector [ each-stream-block ] dip { } like ] [ stream-exemplar concat-as ] bi - ] with-disposal ; + ] with-disposal ; inline + : (stream-contents-by-length-or-block) ( stream -- seq ) dup stream-length - [ (stream-contents-by-length) ] + [ (stream-contents-by-length) ] [ (stream-contents-by-block) ] if* ; inline + : (stream-contents-by-element) ( stream -- seq ) [ [ [ stream-read1 dup ] curry [ ] ] [ stream-exemplar produce-as nip ] bi - ] with-disposal ; + ] with-disposal ; inline : contents ( -- seq ) input-stream get stream-contents ; inline @@ -227,9 +233,9 @@ CONSTANT: each-block-size 65536 [ stream-exemplar ] bi produce-as swap finalize-read-until ; inline PRIVATE> -M: input-stream stream-read-unsafe rot 0 read-loop ; +M: input-stream stream-read-unsafe rot 0 read-loop ; inline M: input-stream stream-read-partial-unsafe stream-read-unsafe ; inline -M: input-stream stream-read-until read-until-loop ; +M: input-stream stream-read-until read-until-loop ; inline M: input-stream stream-readln "\n" swap stream-read-until drop ; inline M: input-stream stream-contents (stream-contents-by-length-or-block) ; inline @@ -253,4 +259,3 @@ M: f stream-write1 2drop ; inline M: f stream-write 2drop ; inline M: f stream-flush drop ; inline M: f stream-nl drop ; inline - diff --git a/core/io/streams/c/c.factor b/core/io/streams/c/c.factor index f05df81cf2..5804360087 100644 --- a/core/io/streams/c/c.factor +++ b/core/io/streams/c/c.factor @@ -42,7 +42,7 @@ M: c-reader stream-read1 dup check-disposed handle>> fgetc ; dup pick member-eq? [ 2nip ] [ , read-until-loop ] if ] [ 2nip - ] if ; + ] if ; inline recursive M: c-reader stream-read-until dup check-disposed