]> gitweb.factorcode.org Git - factor.git/commitdiff
io.binary.fast: remove duplication.
authorJohn Benediktsson <mrjbq7@gmail.com>
Tue, 3 Jun 2014 00:18:20 +0000 (17:18 -0700)
committerJohn Benediktsson <mrjbq7@gmail.com>
Tue, 3 Jun 2014 00:18:20 +0000 (17:18 -0700)
extra/io/binary/fast/fast.factor

index e0de1c77a3205782f88277ef03467395845f1149..ffd5298da9d5b9e6c45a97051dd280043ba98cc7 100644 (file)
@@ -37,20 +37,22 @@ MACRO: reassemble-le ( n -- quot ) le-range reassemble-bytes ;
 :: n-le> ( bytes n -- x )
     bytes n check-length drop n firstn-unsafe n reassemble-le ; inline
 
+<PRIVATE
+: if-endian ( endian bytes seq -- )
+    [
+        compute-native-endianness =
+        [ dup byte-array? ] [ f ] if
+    ] 2dip if ; inline
+PRIVATE>
+
 : 2be> ( bytes -- x )
-    compute-native-endianness big-endian =
-    [ dup byte-array? ] [ f ] if
-    [ c:short deref ] [ 2 n-be> ] if ;
+    big-endian [ c:short deref ] [ 2 n-be> ] if-endian ;
 
 : 4be> ( bytes -- x )
-    compute-native-endianness big-endian =
-    [ dup byte-array? ] [ f ] if
-    [ c:int deref ] [ 4 n-be> ] if ;
+    big-endian [ c:int deref ] [ 4 n-be> ] if-endian ;
 
 : 8be> ( bytes -- x )
-    compute-native-endianness big-endian =
-    [ dup byte-array? ] [ f ] if
-    [ c:longlong deref ] [ 8 n-be> ] if ;
+    big-endian [ c:longlong deref ] [ 8 n-be> ] if-endian ;
 
 : be> ( bytes -- x )
     dup length {
@@ -61,19 +63,13 @@ MACRO: reassemble-le ( n -- quot ) le-range reassemble-bytes ;
     } case ;
 
 : 2le> ( bytes -- x )
-    compute-native-endianness little-endian =
-    [ dup byte-array? ] [ f ] if
-    [ c:short deref ] [ 2 n-le> ] if ;
+    little-endian [ c:short deref ] [ 2 n-le> ] if-endian ;
 
 : 4le> ( bytes -- x )
-    compute-native-endianness little-endian =
-    [ dup byte-array? ] [ f ] if
-    [ c:int deref ] [ 4 n-le> ] if ;
+    little-endian [ c:int deref ] [ 4 n-le> ] if-endian ;
 
 : 8le> ( bytes -- x )
-    compute-native-endianness little-endian =
-    [ dup byte-array? ] [ f ] if
-    [ c:longlong deref ] [ 8 n-le> ] if ;
+    little-endian [ c:longlong deref ] [ 8 n-le> ] if-endian ;
 
 : le> ( bytes -- x )
     dup length {