Skip to content

Commit

Permalink
vocabs.parser: faster name lookup.
Browse files Browse the repository at this point in the history
  • Loading branch information
mrjbq7 committed Aug 14, 2020
1 parent 8cc0909 commit d535b62
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions core/vocabs/parser/parser.factor
Expand Up @@ -182,17 +182,24 @@ TUPLE: ambiguous-use-error name words ;

<PRIVATE

: (lookup-word) ( words name vocab -- words )
words>> (lookup) [ suffix! ] when* ; inline

: (vocab-search) ( name assocs -- words )
[ words>> (lookup) ] with map sift ;
[ V{ } clone ] 2dip [ (lookup-word) ] with each ;

: (vocab-search-qualified) ( name assocs -- words )
[ ":" split1 swap ] dip [ name>> = ] with filter (vocab-search) ;
: (vocab-search-qualified) ( words name assocs -- words )
[ ":" split1 swap ] dip pick [
[ name>> = ] with find nip [ (lookup-word) ] with when*
] [
3drop
] if ;

: (vocab-search-full) ( name assocs -- words )
[ (vocab-search-qualified) ] [ (vocab-search) ] 2bi append ;
[ (vocab-search) ] [ (vocab-search-qualified) ] 2bi ;

: vocab-search ( name manifest -- word/f )
dupd search-vocabs>> sift (vocab-search-full) dup length {
dupd search-vocabs>> (vocab-search-full) dup length {
{ 0 [ 2drop f ] }
{ 1 [ first nip ] }
[
Expand Down

0 comments on commit d535b62

Please sign in to comment.