File tree 2 files changed +31
-6
lines changed
2 files changed +31
-6
lines changed Original file line number Diff line number Diff line change 141
141
(simple-benchmark [coll (array-map a b c d e f)] (-lookup coll e) 1000000 ))
142
142
(println )
143
143
144
+ (println " ;;; array-map w/ inline symbols" )
145
+ (simple-benchmark [coll (array-map )] (assoc coll 'foo 'bar) 1000000 )
146
+ (simple-benchmark [coll (array-map 'foo 'bar)] (-lookup coll 'foo) 1000000 )
147
+ (simple-benchmark [coll (array-map 'foo 'bar)] (assoc coll 'baz 'woz) 1000000 )
148
+ (simple-benchmark [coll (array-map 'foo 'bar 'baz 'woz)] (-lookup coll 'baz) 1000000 )
149
+ (simple-benchmark [coll (array-map 'foo 'bar 'baz 'woz 'lol 'rofl)] (-lookup coll 'lol) 1000000 )
150
+ (println )
151
+
144
152
(def data-atom (atom {:x 0 }))
145
153
146
154
(println " ;;; map / record ops" )
Original file line number Diff line number Diff line change 160
160
(name x)
161
161
\"))
162
162
163
- ; ; TODO: we could optimize, call type constructor & inline all the properties of x - David
163
+ (def ^:const goog-hash-max 0x100000000 )
164
+
165
+ (defn goog-string-hash [s]
166
+ (reduce
167
+ (fn [r c]
168
+ (mod (+ (* 31 r) (int c)) goog-hash-max))
169
+ 0 s))
164
170
165
171
(defmethod emit-constant clojure.lang.Symbol [x]
166
- (emits " cljs.core.symbol(" )
167
- (emit-constant (namespace x))
168
- (emits " ," )
169
- (emit-constant (name x))
170
- (emits " )" ))
172
+ (let [ns (namespace x)
173
+ name (name x)
174
+ symstr (if-not (nil? ns )
175
+ (str ns " /" name)
176
+ name)]
177
+ (emits " new cljs.core.Symbol(" )
178
+ (emit-constant ns )
179
+ (emits " ," )
180
+ (emit-constant name)
181
+ (emits " ," )
182
+ (emit-constant symstr)
183
+ (emits " ," )
184
+ (emit-constant (goog-string-hash symstr))
185
+ (emits " ," )
186
+ (emit-constant nil )
187
+ (emits " )" )))
171
188
172
189
(defn- emit-meta-constant [x & body]
173
190
(if (meta x)
You can’t perform that action at this time.
0 commit comments