[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Guile-commits] 06/07: Speed golf on Scheme put-u8, put-bytevector
From: |
Andy Wingo |
Subject: |
[Guile-commits] 06/07: Speed golf on Scheme put-u8, put-bytevector |
Date: |
Tue, 24 May 2016 20:44:59 +0000 (UTC) |
wingo pushed a commit to branch master
in repository guile.
commit 48dbadd8e60ca6335593e4a93179da3e8de8b34e
Author: Andy Wingo <address@hidden>
Date: Tue May 24 08:37:57 2016 +0200
Speed golf on Scheme put-u8, put-bytevector
* module/ice-9/sports.scm (put-u8, put-bytevector): Speed hack.
---
module/ice-9/sports.scm | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/module/ice-9/sports.scm b/module/ice-9/sports.scm
index 37ea092..86d9a5b 100644
--- a/module/ice-9/sports.scm
+++ b/module/ice-9/sports.scm
@@ -309,13 +309,13 @@
(else (fill-directly pos))))))
(define (put-u8 port byte)
- (when (port-random-access? port)
- (flush-input port))
(let* ((buf (port-write-buffer port))
(bv (port-buffer-bytevector buf))
(end (port-buffer-end buf)))
(unless (<= 0 end (bytevector-length bv))
(error "not an output port" port))
+ (when (and (eq? (port-buffer-cur buf) end) (port-random-access? port))
+ (flush-input port))
(bytevector-u8-set! bv end byte)
(set-port-buffer-end! buf (1+ end))
(when (= (1+ end) (bytevector-length bv)) (flush-output port))))
@@ -324,14 +324,14 @@
(count (- (bytevector-length src) start)))
(unless (<= 0 start (+ start count) (bytevector-length src))
(error "invalid start/count" start count))
- (when (port-random-access? port)
- (flush-input port))
(let* ((buf (port-write-buffer port))
(bv (port-buffer-bytevector buf))
(size (bytevector-length bv))
(cur (port-buffer-cur buf))
(end (port-buffer-end buf))
(buffered (- end cur)))
+ (when (and (eq? cur end) (port-random-access? port))
+ (flush-input port))
(cond
((<= size count)
;; The write won't fit in the buffer at all; write directly.
- [Guile-commits] branch master updated (6bf7ec0 -> 47918f3), Andy Wingo, 2016/05/24
- [Guile-commits] 02/07: close-port implementation in sports, Andy Wingo, 2016/05/24
- [Guile-commits] 06/07: Speed golf on Scheme put-u8, put-bytevector,
Andy Wingo <=
- [Guile-commits] 07/07: Speed up scm_c_write / scm_lfwrite, Andy Wingo, 2016/05/24
- [Guile-commits] 01/07: Add force-output to sports, Andy Wingo, 2016/05/24
- [Guile-commits] 04/07: `put-bytevector' in Scheme, Andy Wingo, 2016/05/24
- [Guile-commits] 03/07: Wire up non-blocking support in sport writes, Andy Wingo, 2016/05/24
- [Guile-commits] 05/07: Add put-u8 implementation in Scheme, Andy Wingo, 2016/05/24