]> gitweb.factorcode.org Git - factor.git/commitdiff
xml: 10-12% faster benchmark through cleanup and minor refactoring.
authorJohn Benediktsson <mrjbq7@gmail.com>
Fri, 13 Jul 2012 02:06:37 +0000 (19:06 -0700)
committerJohn Benediktsson <mrjbq7@gmail.com>
Fri, 13 Jul 2012 02:06:37 +0000 (19:06 -0700)
basis/xml/data/data.factor
basis/xml/elements/elements.factor
basis/xml/name/name.factor
basis/xml/tokenize/tokenize.factor
basis/xml/writer/writer.factor
basis/xml/xml.factor

index a76c46dd0a05622698787cd153827ec2b8c482db..9752d19bf247d03e392e4e6803427d8c316fc196 100644 (file)
@@ -2,7 +2,8 @@
 ! See http://factorcode.org/license.txt for BSD license.
 USING: kernel sequences sequences.private assocs arrays
 delegate.protocols delegate vectors accessors multiline
-macros words quotations combinators slots fry strings ;
+macros words quotations combinators slots fry strings
+combinators.short-circuit ;
 IN: xml.data
 
 TUPLE: interpolated var ;
@@ -18,9 +19,11 @@ C: <name> name
     2dup and [ = ] [ 2drop t ] if ;
 
 : names-match? ( name1 name2 -- ? )
-    [ [ space>> ] bi@ ?= ]
-    [ [ url>> ] bi@ ?= ]
-    [ [ main>> ] bi@ ?= ] 2tri and and ;
+    {
+        [ [ space>> ] bi@ ?= ]
+        [ [ url>> ] bi@ ?= ]
+        [ [ main>> ] bi@ ?= ]
+    } 2&& ;
 
 : <simple-name> ( string -- name )
     "" swap f <name> ;
index 3ef1e669f1a5463e076ed45b1a26613fe2a3a504..4de4fc36793832c8a3036dc94ed7b9fb4c6a86c5 100644 (file)
@@ -18,29 +18,26 @@ IN: xml.elements
 : interpolate-quote ( -- interpolated )
     [ quoteless-attr ] take-interpolated ;
 
-: parse-attr ( -- )
-    parse-name pass-blank "=" expect pass-blank
-    get-char CHAR: < eq?
-    [ "<-" expect interpolate-quote ]
-    [ t parse-quote* ] if 2array , ;
-
 : start-tag ( -- name ? )
     #! Outputs the name and whether this is a closing tag
     get-char CHAR: / eq? dup [ next ] when
     parse-name swap ;
 
-: (middle-tag) ( -- )
-    pass-blank version-1.0? get-char name-start?
-    [ parse-attr (middle-tag) ] when ;
-
 : assure-no-duplicates ( attrs-alist -- attrs-alist )
     H{ } clone 2dup '[ swap _ push-at ] assoc-each
     [ nip length 2 >= ] { } assoc-filter-as
     [ first first2 duplicate-attr ] unless-empty ;
 
+: parse-attr ( -- array )
+    parse-name pass-blank "=" expect pass-blank
+    get-char CHAR: < eq?
+    [ "<-" expect interpolate-quote ]
+    [ t parse-quote* ] if 2array ;
+
 : middle-tag ( -- attrs-alist )
-    ! f make will make a vector if it has any elements
-    [ (middle-tag) ] f make pass-blank
+    ! f produce-as will make a vector if it has any elements
+    [ pass-blank version-1.0? get-char name-start? ]
+    [ parse-attr ] f produce-as pass-blank
     dup length 1 > [ assure-no-duplicates ] when ;
 
 : end-tag ( name attrs-alist -- tag )
index 7f796223926e6871499d12bcc688307c0a012307..95557cb2c46067a93bf3196883a2a6b81b042476 100644 (file)
@@ -2,7 +2,7 @@
 ! See http://factorcode.org/license.txt for BSD license.
 USING: kernel namespaces accessors xml.tokenize xml.data assocs
 xml.errors xml.char-classes combinators.short-circuit splitting
-fry xml.state sequences combinators ascii ;
+fry xml.state sequences combinators ascii math ;
 IN: xml.name
 
 ! XML namespace processing: ns = namespace
@@ -53,11 +53,19 @@ SYMBOL: ns-stack
         } 2&&
     ] if-empty ;
 
+: maybe-name ( space main -- name/f )
+    2dup {
+        [ drop valid-name? ]
+        [ nip valid-name? ]
+    } 2&& [ f <name> ] [ 2drop f ] if ;
+
 : prefixed-name ( str -- name/f )
-    ":" split dup length 2 = [
-        [ [ valid-name? ] all? ]
-        [ first2 f <name> ] bi and
-    ] [ drop f ] if ;
+    CHAR: : over index [
+        CHAR: : 2over 1 + swap index-from
+        [ 2drop f ]
+        [ [ head ] [ 1 + tail ] 2bi maybe-name ]
+        if
+    ] [ drop f ] if* ;
 
 : interpret-name ( str -- name )
     dup prefixed-name [ ] [
index ee7ffdf63963abe922ee640d9377e42a16e05daa..ebabd2c893ec7f2bf282e648a6b5e20d89d0b07d 100644 (file)
@@ -3,16 +3,17 @@
 USING: namespaces xml.state kernel sequences accessors
 xml.char-classes xml.errors math io sbufs fry strings ascii
 xml.entities assocs splitting math.parser
-locals combinators arrays hints ;
+locals combinators combinators.short-circuit arrays hints ;
 IN: xml.tokenize
 
 ! * Basic utility words
 
 : assure-good-char ( spot ch -- )
     [
-        over
-        [ version-1.0?>> over text? not ]
-        [ check>> ] bi and
+        over {
+            [ version-1.0?>> over text? not ]
+            [ check>> ]
+        } 1&&
         [
             [ [ 1 + ] change-column drop ] dip
             disallowed-char
index 3a23108dd5a6fc42e73688f7bd2e46b4797211ed..6296e4cfbf36988ddd514c33b24c5fb3916612eb 100644 (file)
@@ -34,7 +34,7 @@ SYMBOL: indentation
 : ?filter-children ( children -- no-whitespace )\r
     xml-pprint? get [\r
         [ dup string? [ [ blank? ] trim ] when ] map\r
-        [ [ empty? ] [ string? ] bi and not ] filter\r
+        [ "" = not ] filter\r
     ] when ;\r
 \r
 PRIVATE>\r
index 66780e9d67288e210167ca94e27a91cba4f7fb10..22e1a850b70d03227c61093fce093933bca2d312 100644 (file)
@@ -89,7 +89,7 @@ M: closer process
     [ drop default-prolog ] unless ;
 
 : cut-prolog ( seq -- newseq )
-    [ [ prolog? not ] [ "" = not ] bi and ] filter ;
+    [ { [ prolog? not ] [ "" = not ] } 1&& ] filter ;
 
 : make-xml-doc ( seq -- xml-doc )
     [ get-prolog ] keep