From a8e9b5768587272212ed24d0028862437d03297f Mon Sep 17 00:00:00 2001
From: John Benediktsson <mrjbq7@gmail.com>
Date: Fri, 13 Aug 2010 19:28:44 -0700
Subject: [PATCH] tools.completion: making completions a lot faster using make.

---
 basis/tools/completion/completion-docs.factor | 10 +++++++++-
 basis/tools/completion/completion.factor      | 20 +++++++++++++------
 2 files changed, 23 insertions(+), 7 deletions(-)

diff --git a/basis/tools/completion/completion-docs.factor b/basis/tools/completion/completion-docs.factor
index 7d5ebf8910..87e675efa6 100644
--- a/basis/tools/completion/completion-docs.factor
+++ b/basis/tools/completion/completion-docs.factor
@@ -1,5 +1,5 @@
 USING: help.markup help.syntax strings generic vectors assocs
-math ;
+math make ;
 IN: tools.completion
 
 ARTICLE: "tools.completion" "Fuzzy completion"
@@ -50,6 +50,14 @@ HELP: completion
     }
 } ;
 
+HELP: completion,
+{ $values { "short" string } { "candidate" "a pair " { $snippet "{ obj full }" } } }
+{ $description
+    "Adds the result of " { $link completion }
+    " to the end of the sequence being constructed by " { $link make }
+    " if the score is positive."
+} ;
+
 HELP: completions
 { $values { "short" string } { "candidates" "a sequence of pairs of the shape " { $snippet "{ obj full }" } } { "seq" "a sequence of pairs of the shape " { $snippet "{ score obj }" } } }
 { $description "Calls " { $link completion } " to produce a sequence of " { $snippet "{ score obj }" } " pairs, then calls " { $link rank-completions } " to sort them and discard the low 33%." } ;
diff --git a/basis/tools/completion/completion.factor b/basis/tools/completion/completion.factor
index d62c192ac1..abb9ecfe39 100644
--- a/basis/tools/completion/completion.factor
+++ b/basis/tools/completion/completion.factor
@@ -1,9 +1,11 @@
 ! Copyright (C) 2005, 2009 Slava Pestov.
 ! See http://factorcode.org/license.txt for BSD license.
-USING: accessors kernel arrays sequences math namespaces strings io
-fry vectors words assocs combinators sorting unicode.case
-unicode.categories math.order vocabs vocabs.hierarchy unicode.data
-locals ;
+
+USING: accessors arrays assocs combinators fry io kernel locals
+make math math.order namespaces sequences sorting strings
+unicode.case unicode.categories unicode.data vectors vocabs
+vocabs.hierarchy words ;
+
 IN: tools.completion
 
 :: (fuzzy) ( accum i full ch -- accum i full ? )
@@ -64,9 +66,14 @@ IN: tools.completion
 : completion ( short candidate -- result )
     [ second >lower swap complete ] keep 2array ;
 
+: completion, ( short candidate -- )
+    completion dup first 0 > [ , ] [ drop ] if ;
+
 : completions ( short candidates -- seq )
-    [ ] [ [ >lower ] dip [ completion ] with map rank-completions ]
-    bi-curry if-empty ;
+    [ ] [
+        [ >lower ] dip [ [ completion, ] with each ] { } make
+        rank-completions
+    ] bi-curry if-empty ;
 
 : name-completions ( str seq -- seq' )
     [ dup name>> ] { } map>assoc completions ;
@@ -79,3 +86,4 @@ IN: tools.completion
 
 : chars-matching ( str -- seq )
     name-map keys dup zip completions ;
+