]> gitweb.factorcode.org Git - factor.git/commitdiff
csv: faster, only use make when field contains quotes or newlines.
authorJohn Benediktsson <mrjbq7@gmail.com>
Sun, 15 Jul 2012 16:50:51 +0000 (09:50 -0700)
committerJohn Benediktsson <mrjbq7@gmail.com>
Sun, 15 Jul 2012 16:50:51 +0000 (09:50 -0700)
basis/csv/csv.factor

index daddca9e25741164fd3d12b3ad2890fbc3638a0e..757d60613893fbd6e7b6651917055262562929d1 100644 (file)
@@ -24,19 +24,6 @@ DEFER: quoted-field
 MEMO: (quoted-field) ( delimiter -- delimiter' )
     "\"\n" swap suffix ; inline
 
-: not-quoted-field ( -- endchar )
-    delimiter> (quoted-field) read-until
-    dup CHAR: " =
-    [ 2drop quoted-field ]
-    [
-        swap dup {
-            [ ?first blank? ]
-            [ ?last blank? ]
-        } 1||
-        [ [ blank? ] trim ] when %
-    ]
-    if ;
-
 : maybe-escaped-quote ( -- endchar )
     read1 dup {
         { CHAR: "    [ , quoted-field ] }
@@ -50,7 +37,18 @@ MEMO: (quoted-field) ( delimiter -- delimiter' )
     drop % maybe-escaped-quote ;
 
 : field ( -- sep string )
-    [ not-quoted-field ] "" make  ;
+    delimiter> (quoted-field) read-until
+    dup CHAR: " = [
+        2drop [ quoted-field ] "" make
+    ] [
+        swap [ "" ] [
+            dup {
+                [ ?first blank? ]
+                [ ?last blank? ]
+            } 1||
+            [ [ blank? ] trim ] when
+        ] if-empty
+    ] if ;
 
 : (row) ( -- sep )
     f delimiter> '[ dup _ = ]