Open every source file just once. This make code work ~20x faster

db4
Alfredo Beaumont 2008-07-11 10:53:51 +02:00
parent cec5291ed4
commit 4cb68c4a4d
1 changed files with 9 additions and 9 deletions

View File

@ -5,7 +5,7 @@
! Alfredo Beaumont <alfredo.beaumont@gmail.com> ! Alfredo Beaumont <alfredo.beaumont@gmail.com>
USING: kernel sequences sorting assocs words prettyprint ctags USING: kernel sequences sorting assocs words prettyprint ctags
io.encodings.ascii io.files math math.parser namespaces strings locals io.encodings.ascii io.files math math.parser namespaces strings locals
shuffle io.backend memoize ; shuffle io.backend arrays ;
IN: ctags.etags IN: ctags.etags
: ctag-path ( alist -- path ) : ctag-path ( alist -- path )
@ -39,20 +39,20 @@ IN: ctags.etags
] 2keep line>bytes + ] 2keep line>bytes +
] if ; ] if ;
: file>bytes ( n path -- bytes ) : file>lines ( resource -- lines )
ascii file-lines lines>bytes ; ascii file-lines ;
: etag ( path seq -- str ) : etag ( lines seq -- str )
[ [
dup first ?word-name % dup first ?word-name %
1 HEX: 7f <string> % 1 HEX: 7f <string> %
second dup number>string % second dup number>string %
1 CHAR: , <string> % 1 CHAR: , <string> %
2 - swap file>bytes number>string % 2 - swap lines>bytes number>string %
] "" make ; ] "" make ;
: etag-entry ( alist -- alist path ) : etag-entry ( alist -- alist array )
[ first ] keep swap ; [ first ] keep swap [ file>lines ] keep 2array ;
: vector-length ( vector -- n ) : vector-length ( vector -- n )
0 [ length + ] reduce ; 0 [ length + ] reduce ;
@ -73,9 +73,9 @@ SYMBOL: resource
{ } swap [ { } swap [
etag-entry resource [ etag-entry resource [
second [ second [
resource get swap etag resource get first swap etag
] map dup vector-length ] map dup vector-length
resource get resource get second
] with-variable ] with-variable
etag-header append etag-header append
] each ; ] each ;