File tree Expand file tree Collapse file tree 2 files changed +36
-8
lines changed
libraries/sdk/src/main/starfederation/datastar/clojure/api Expand file tree Collapse file tree 2 files changed +36
-8
lines changed Original file line number Diff line number Diff line change 3232 " Add an option `v` line to the transient `data-lines!` vector.
3333
3434 Args:
35- - `data-lines`: a transient vector of data-lines that will be written in a sse
35+ - `data-lines! `: a transient vector of data-lines that will be written in a sse
3636 event
3737 - `prefix`: The Datastar specific preffix for that line
3838 - `v`: the value for that line
4343
4444(defn add-data-lines!
4545 " Add several data-lines to the `data-lines!` transient vector."
46- [data-lines! prefix text]
47- (reduce
48- ( fn [acc part ]
49- ( conj! acc ( str prefix part)))
50- data-lines!
51- ( string/split-lines text )))
52-
46+ [data-lines! prefix ^String text]
47+ (let [stream ( .lines text)
48+ i ( .iterator stream) ]
49+ ( loop [ acc data-lines!]
50+ ( if ( .hasNext i)
51+ ( recur ( conj! acc ( str prefix ( .next i) )))
52+ acc))))
5353
5454(defn add-boolean-option?
5555 " Utility used to test whether an boolean option should result in a sse event
Original file line number Diff line number Diff line change 1+ (ns bench.split
2+ (:require
3+ [clojure.string :as string]
4+ [starfederation.datastar.clojure.api.common :as c]))
5+
6+
7+ (defn old-datalines [data-lines! prefix text]
8+ (reduce
9+ (fn [acc part]
10+ (conj! acc (str prefix part)))
11+ data-lines!
12+ (string/split-lines text)))
13+
14+
15+ (def input " hello there\n wold !\r\n How are \r you \n today" )
16+ (def input-big (apply str (repeat 100 input)))
17+
18+ (defn bench [f input]
19+ (println " ---------------------------------------" )
20+ (dotimes [_ 20 ]
21+ (time
22+ (dotimes [_ 10000 ]
23+ (f (transient []) " elements " input)))))
24+
25+
26+ (comment
27+ (bench old-datalines input-big)
28+ (bench c/add-data-lines! input-big))
You can’t perform that action at this time.
0 commit comments