From fbaa36c3a7e249cbcf0adabace8ea70db7ff9b24 Mon Sep 17 00:00:00 2001 From: Chris Hanson Date: Thu, 27 Apr 2017 22:42:43 -0700 Subject: [PATCH] Use index procedures to simplify read-bytevector!. --- src/runtime/binary-port.scm | 27 +++++++-------------------- 1 file changed, 7 insertions(+), 20 deletions(-) diff --git a/src/runtime/binary-port.scm b/src/runtime/binary-port.scm index dc8d16b4f..785e0c550 100644 --- a/src/runtime/binary-port.scm +++ b/src/runtime/binary-port.scm @@ -400,26 +400,13 @@ USA. (make-bytevector 0)))) (define (read-bytevector! bytevector #!optional port start end) - (let ((ib (check-input-port port 'read-bytevector!)) - (end - (if (default-object? end) - (bytevector-length bytevector) - (begin - (guarantee index-fixnum? end 'read-bytevector!) - (if (not (fix:<= end (bytevector-length bytevector))) - (error:bad-range-argument end 'read-bytevector)) - end)))) - (let ((start - (if (default-object? start) - 0 - (begin - (guarantee index-fixnum? start 'read-bytevector!) - (if (not (fix:<= start end)) - (error:bad-range-argument start 'read-bytevector!)) - start)))) - (if (fix:< start end) - (%read-bytevector! ib bytevector start end 'read-bytevector!) - 0)))) + (let* ((caller 'read-bytevector!) + (ib (check-input-port port caller)) + (end (fix:end-index end (bytevector-length bytevector) caller)) + (start (fix:start-index start end caller))) + (if (fix:< start end) + (%read-bytevector! ib bytevector start end caller) + 0))) (define (%read-bytevector! ib bytevector start end caller) -- 2.25.1