Skip to content

Commit d694575

Browse files
committed
faster slow-write-string
1 parent cc154d5 commit d694575

2 files changed

Lines changed: 9 additions & 4 deletions

File tree

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,8 @@ Change Log
156156
* Add [DJSON-46]: In `read`, add `:extra-data-fn` that can be provided to cause an eof check after value is read
157157
* Add [DJSON-54]: In `write`, add custom fallback fn for writing unknown types
158158
* Perf [DJSON-61]: Faster string writing when string is "simple"
159+
* Perf: Faster string writing when string is not simple
160+
* Perf: Faster `read-str`
159161
* Release [2.4.0] on 2021-Jul-12
160162
* Fix [DJSON-52]: Remove Classloader workaround to support Clojure 1.2.x and below
161163
* Fix [DJSON-53]: Move deprecated API functions from compat ns into main ns

src/main/clojure/clojure/data/json.clj

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -562,25 +562,28 @@
562562
shorts))
563563

564564
(defn- slow-write-string [^CharSequence s ^Appendable out options]
565-
(let [decoder codepoint-decoder]
565+
(let [decoder codepoint-decoder
566+
slash (get options :escape-slash)
567+
escape-js-separators (get options :escape-js-separators)
568+
escape-unicode (get options :escape-unicode)]
566569
(dotimes [i (.length s)]
567570
(let [cp (int (.charAt s i))]
568571
(if (< cp 128)
569572
(case (aget decoder cp)
570573
0 (.append out (char cp))
571574
1 (do (.append out (char (codepoint \\))) (.append out (char cp)))
572-
2 (.append out (if (get options :escape-slash) "\\/" "/"))
575+
2 (.append out (if slash "\\/" "/"))
573576
3 (.append out "\\b")
574577
4 (.append out "\\f")
575578
5 (.append out "\\n")
576579
6 (.append out "\\r")
577580
7 (.append out "\\t")
578581
8 (->hex-string out cp))
579582
(codepoint-case cp
580-
:js-separators (if (get options :escape-js-separators)
583+
:js-separators (if escape-js-separators
581584
(->hex-string out cp)
582585
(.append out (char cp)))
583-
(if (get options :escape-unicode)
586+
(if escape-unicode
584587
(->hex-string out cp) ; Hexadecimal-escaped
585588
(.append out (char cp)))))))))
586589

0 commit comments

Comments
 (0)