]> gitweb.factorcode.org Git - factor.git/commitdiff
tools.completion: speed up apropos by 35%. Fixes #101.
authorJohn Benediktsson <mrjbq7@gmail.com>
Tue, 13 Sep 2011 16:13:02 +0000 (09:13 -0700)
committerJohn Benediktsson <mrjbq7@gmail.com>
Tue, 13 Sep 2011 16:13:02 +0000 (09:13 -0700)
basis/tools/completion/completion.factor

index abb9ecfe39eccbcbddc9785a960dc2ca9f77c7d8..ab675c82245294fb9d13903ba4775905598a87c0 100644 (file)
@@ -8,8 +8,14 @@ vocabs.hierarchy words ;
 
 IN: tools.completion
 
+<PRIVATE
+
+: smart-index-from ( obj i seq -- n/f )
+    rot [ ch>lower ] [ ch>upper ] bi
+    [ eq? ] bi-curry@ [ bi or ] 2curry find-from drop ;
+
 :: (fuzzy) ( accum i full ch -- accum i full ? )
-    ch i full index-from [
+    ch i full smart-index-from [
         :> i i accum push
         accum i 1 + full t
     ] [
@@ -64,14 +70,16 @@ IN: tools.completion
     dupd fuzzy score max ;
 
 : completion ( short candidate -- result )
-    [ second >lower swap complete ] keep 2array ;
+    [ second swap complete ] keep 2array ;
 
 : completion, ( short candidate -- )
     completion dup first 0 > [ , ] [ drop ] if ;
 
+PRIVATE>
+
 : completions ( short candidates -- seq )
     [ ] [
-        [ >lower ] dip [ [ completion, ] with each ] { } make
+        [ [ completion, ] with each ] { } make
         rank-completions
     ] bi-curry if-empty ;