Use index procedures to simplify read-bytevector!.
authorChris Hanson <org/chris-hanson/cph>
Fri, 28 Apr 2017 05:42:43 +0000 (22:42 -0700)
committerChris Hanson <org/chris-hanson/cph>
Fri, 28 Apr 2017 05:42:43 +0000 (22:42 -0700)
src/runtime/binary-port.scm

index dc8d16b4f98cf4cd2cf06374bfa40de158d6332f..785e0c550fd960e9b094b1fb8b898bbfa53231e6 100644 (file)
@@ -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)