Skip to content

Commit a8b7b48

Browse files
committed
* pr-writer-impl
- .toString vs. str - no lazy seq - write-all -> write-all-array
1 parent 34203d6 commit a8b7b48

File tree

1 file changed

+50
-37
lines changed

1 file changed

+50
-37
lines changed

src/main/cljs/cljs/core.cljs

Lines changed: 50 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -10495,6 +10495,13 @@ reduces them without incurring seq initialization"
1049510495
(doseq [s ss]
1049610496
(-write writer s)))
1049710497

10498+
(defn write-all-array [writer arr]
10499+
(let [len (alength arr)]
10500+
(loop [i 0]
10501+
(when (< i len)
10502+
(-write writer (aget arr i))
10503+
(recur (inc i))))))
10504+
1049810505
(defn string-print [x]
1049910506
(when (nil? *print-fn*)
1050010507
(throw (js/Error. "No *print-fn* fn set for evaluation environment")))
@@ -10516,10 +10523,9 @@ reduces them without incurring seq initialization"
1051610523

1051710524
(defn ^:private quote-string
1051810525
[s]
10519-
(str \"
10520-
(.replace s (js/RegExp "[\\\\\"\b\f\n\r\t]" "g")
10521-
(fn [match] (unchecked-get char-escapes match)))
10522-
\"))
10526+
(let [s' ^string (.replace s (js/RegExp "[\\\\\"\b\f\n\r\t]" "g")
10527+
(fn [match] (unchecked-get char-escapes match)))]
10528+
(str \" s' \")))
1052310529

1052410530
(declare print-map)
1052510531

@@ -10548,23 +10554,27 @@ reduces them without incurring seq initialization"
1054810554
(-pr-writer obj writer opts)
1054910555

1055010556
(or (true? obj) (false? obj))
10551-
(-write writer (str obj))
10557+
(-write writer (.toString obj))
1055210558

1055310559
(number? obj)
1055410560
(-write writer
1055510561
(cond
1055610562
^boolean (js/isNaN obj) "##NaN"
1055710563
(identical? obj js/Number.POSITIVE_INFINITY) "##Inf"
1055810564
(identical? obj js/Number.NEGATIVE_INFINITY) "##-Inf"
10559-
:else (str obj)))
10565+
:else (.toString obj)))
1056010566

1056110567
(object? obj)
1056210568
(do
1056310569
(-write writer "#js ")
1056410570
(print-map
10565-
(map (fn [k]
10566-
(MapEntry. (cond-> k (some? (re-matches #"[A-Za-z_\*\+\?!\-'][\w\*\+\?!\-']*" k)) keyword) (unchecked-get obj k) nil))
10567-
(js-keys obj))
10571+
(prim-seq
10572+
(.map
10573+
(fn [k]
10574+
(MapEntry.
10575+
(cond-> k (some? (re-matches #"[A-Za-z_\*\+\?!\-'][\w\*\+\?!\-']*" k)) keyword)
10576+
(unchecked-get obj k) nil))
10577+
(js-keys obj)))
1056810578
pr-writer writer opts))
1056910579

1057010580
(array? obj)
@@ -10580,45 +10590,48 @@ reduces them without incurring seq initialization"
1058010590
name (if (or (nil? name) (gstring/isEmpty name))
1058110591
"Function"
1058210592
name)]
10583-
(write-all writer "#object[" name
10584-
(if *print-fn-bodies*
10585-
(str " \"" (str obj) "\"")
10586-
"")
10587-
"]"))
10593+
(write-all-array writer
10594+
(array
10595+
"#object[" name
10596+
(if *print-fn-bodies*
10597+
(str " \"" ^string (.toString obj) "\"")
10598+
"")
10599+
"]")))
1058810600

1058910601
(instance? js/Date obj)
1059010602
(let [normalize (fn [n len]
10591-
(loop [ns (str n)]
10603+
(loop [ns (.toString n)]
1059210604
(if (< (count ns) len)
10593-
(recur (str "0" ns))
10605+
(recur (str "0" ^string ns))
1059410606
ns)))]
10595-
(write-all writer
10596-
"#inst \""
10597-
(normalize (.getUTCFullYear obj) 4) "-"
10598-
(normalize (inc (.getUTCMonth obj)) 2) "-"
10599-
(normalize (.getUTCDate obj) 2) "T"
10600-
(normalize (.getUTCHours obj) 2) ":"
10601-
(normalize (.getUTCMinutes obj) 2) ":"
10602-
(normalize (.getUTCSeconds obj) 2) "."
10603-
(normalize (.getUTCMilliseconds obj) 3) "-"
10604-
"00:00\""))
10605-
10606-
(regexp? obj) (write-all writer "#\"" (.-source obj) "\"")
10607-
10608-
(js-symbol? obj) (write-all writer "#object[" (.toString obj) "]" )
10607+
(write-all-array writer
10608+
(array
10609+
"#inst \""
10610+
(normalize (.getUTCFullYear obj) 4) "-"
10611+
(normalize (inc (.getUTCMonth obj)) 2) "-"
10612+
(normalize (.getUTCDate obj) 2) "T"
10613+
(normalize (.getUTCHours obj) 2) ":"
10614+
(normalize (.getUTCMinutes obj) 2) ":"
10615+
(normalize (.getUTCSeconds obj) 2) "."
10616+
(normalize (.getUTCMilliseconds obj) 3) "-"
10617+
"00:00\"")))
10618+
10619+
(regexp? obj) (write-all-array writer (array "#\"" (.-source obj) "\""))
10620+
10621+
(js-symbol? obj) (write-all-array writer (array "#object[" (.toString obj) "]"))
1060910622

1061010623
:else
1061110624
(if (some-> obj .-constructor .-cljs$lang$ctorStr)
10612-
(write-all writer
10613-
"#object[" (.replace (.. obj -constructor -cljs$lang$ctorStr)
10614-
(js/RegExp. "/" "g") ".") "]")
10625+
(write-all-array writer
10626+
(array "#object[" (.replace (.. obj -constructor -cljs$lang$ctorStr)
10627+
(js/RegExp. "/" "g") ".") "]"))
1061510628
(let [name (some-> obj .-constructor .-name)
1061610629
name (if (or (nil? name) (gstring/isEmpty name))
1061710630
"Object"
1061810631
name)]
1061910632
(if (nil? (. obj -constructor))
10620-
(write-all writer "#object[" name "]")
10621-
(write-all writer "#object[" name " " (str obj) "]"))))))))
10633+
(write-all-array writer (array "#object[" name "]"))
10634+
(write-all-array writer (array "#object[" name " " (.toString obj) "]")))))))))
1062210635

1062310636
(defn- pr-writer
1062410637
"Prefer this to pr-seq, because it makes the printing function
@@ -10744,15 +10757,15 @@ reduces them without incurring seq initialization"
1074410757
(recur new-ns entries (assoc lm (strip-ns k) v)))))
1074510758
[ns lm]))))
1074610759

10747-
(defn print-prefix-map [prefix m print-one writer opts]
10760+
(defn print-prefix-map [^string prefix m print-one writer opts]
1074810761
(pr-sequential-writer
1074910762
writer
1075010763
(fn [e w opts]
1075110764
(do (print-one (key e) w opts)
1075210765
(-write w \space)
1075310766
(print-one (val e) w opts)))
1075410767
(str prefix "{") ", " "}"
10755-
opts (seq m)))
10768+
opts (-seq m)))
1075610769

1075710770
(defn print-map [m print-one writer opts]
1075810771
(let [[ns lift-map] (when (map? m)

0 commit comments

Comments
 (0)