]> gitweb.factorcode.org Git - factor.git/commitdiff
generic.math: eliminate a redundant fixnum check, separate out the fixnum dispatch...
authorJohn Benediktsson <mrjbq7@gmail.com>
Fri, 6 Sep 2013 20:50:00 +0000 (13:50 -0700)
committerJohn Benediktsson <mrjbq7@gmail.com>
Fri, 6 Sep 2013 20:50:00 +0000 (13:50 -0700)
core/generic/math/math.factor

index 67701f2fb9e76a89ec8a2f59c40268439c19c109..20654983242d9180033fc6d1fe281903c32459ce 100644 (file)
@@ -97,6 +97,14 @@ SYMBOL: generic-word
     [ [ { ratio complex } ] dip make-math-method-table tuple-dispatch ] 2bi
     tuple swap 2array prefix tag-dispatch ; inline
 
+: fixnum-dispatch ( word quot -- word quot' )
+    [ dup fixnum bootstrap-word dup math-method ]
+    [
+        dup length 3 - cut unclip
+        [ length 2 - ] [ nth ] bi prefix append
+    ] bi*
+    [ if ] 2curry [ 2dup both-fixnums? ] prepend ;
+
 PRIVATE>
 
 SINGLETON: math-combination
@@ -106,18 +114,14 @@ M: math-combination make-default-method
 
 M: math-combination perform-combination
     drop dup generic-word [
-        dup
-        [ fixnum bootstrap-word dup math-method ]
-        [
-            [ over ] [
-                dup math-class? [
-                    [ dup ] [ math-method ] with with math-dispatch-step
-                ] [
-                    drop object-method
-                ] if
-            ] with math-dispatch-step
-        ] bi
-        [ if ] 2curry [ 2dup both-fixnums? ] prepend
+        dup [ over ] [
+            dup math-class? [
+                [ dup ] [ math-method ] with with math-dispatch-step
+            ] [
+                drop object-method
+            ] if
+        ] with math-dispatch-step
+        fixnum-dispatch
         define
     ] with-variable ;