]> gitweb.factorcode.org Git - factor.git/commitdiff
Open-code member? test
authorSlava Pestov <slava@factorcode.org>
Sat, 8 Dec 2007 22:45:51 +0000 (17:45 -0500)
committerSlava Pestov <slava@factorcode.org>
Sat, 8 Dec 2007 22:45:51 +0000 (17:45 -0500)
core/combinators/combinators.factor
core/optimizer/known-words/known-words.factor
core/optimizer/math/math.factor
extra/help/handbook/handbook.factor

index 0e214c412ac1cfbbf416ec1595f15d3818980282..2c418768c67ee78e8e022e557ce0d06c85a6fb48 100755 (executable)
@@ -79,6 +79,10 @@ M: sequence hashcode*
     dup empty? [
         drop
     ] [
-        hash-case-table hash-dispatch-quot
-        [ dup hashcode >fixnum ] swap append
+        dup length 4 <= [
+            case>quot
+        ] [
+            hash-case-table hash-dispatch-quot
+            [ dup hashcode >fixnum ] swap append
+        ] if
     ] if ;
index 40752c58a55e99fc06adc35e1556adb1567f7702..e9e4c53632bdfe6cb5f7a06294300c02fca36a31 100755 (executable)
@@ -8,7 +8,7 @@ assocs quotations sequences.private io.binary io.crc32
 io.streams.string layouts splitting math.intervals
 math.floats.private tuples tuples.private classes
 optimizer.def-use optimizer.backend optimizer.pattern-match
-float-arrays combinators.private ;
+float-arrays combinators.private combinators ;
 
 ! the output of <tuple> and <tuple-boa> has the class which is
 ! its second-to-last input
@@ -50,6 +50,20 @@ float-arrays combinators.private ;
     { [ dup disjoint-eq? ] [ [ f ] inline-literals ] }
 } define-optimizers
 
+: literal-member? ( #call -- ? )
+    node-in-d peek dup value?
+    [ value-literal sequence? ] [ drop f ] if ;
+
+: member-quot ( seq -- newquot )
+    [ [ t ] ] { } map>assoc [ drop f ] add [ nip case ] curry ;
+
+: expand-member ( #call -- )
+    dup node-in-d peek value-literal member-quot splice-quot ;
+
+\ member? {
+    { [ dup literal-member? ] [ expand-member ] }
+} define-optimizers
+
 ! if the result of eq? is t and the second input is a literal,
 ! the first input is equal to the second
 \ eq? [
index 0ea1f1316ba079d1d75e3227106a131dff1be72c..3389b1b84e5c12b56bae67a649c900aac29eefdd 100755 (executable)
@@ -111,7 +111,7 @@ optimizer.def-use generic.standard ;
 
 : post-process ( class interval node -- classes intervals )
     dupd won't-overflow?
-    [ >r dup { f integer } memq? [ drop fixnum ] when r> ] when
+    [ >r dup { f integer } member? [ drop fixnum ] when r> ] when
     [ dup [ 1array ] when ] 2apply ;
 
 : math-output-interval-1 ( node word -- interval )
index 0c003573a95cd45c3188515942116f579d691dce..30f8d0f29fae6eda02e312ddbdc959ef33e97932 100755 (executable)
@@ -235,6 +235,7 @@ ARTICLE: "changes" "Changes in the latest release"
     { "New, efficient implementations of " { $link bit? } " and " { $link log2 } " runs in constant time for large bignums" }
     { "New " { $link big-random } " word for generating large random numbers quickly" }
     { "Improved profiler no longer has to be explicitly enabled and disabled with a full recompile; instead, the " { $link profile } " word can be used at any time, and it dynamically patches words to increment call counts. There is no overhead when the profiler is not in use." }
+    { "Calls to " { $link member? } " with a literal sequence are now open-coded. If there are four or fewer elements, a series of conditionals are generated; if there are more than four elements, there is a hash dispatch followed by conditionals in each branch." }
 }
 { $subheading "IO" }
 { $list