_评论者:gshayban_
复现代码
(def C (atom 0))
;; 重新扩展以进行排错
(extend-protocol clojure.core.protocols/IKVReduce
;;slow path default
clojure.lang.IPersistentMap
(kv-reduce
[amap f init]
(swap! C inc)
(reduce (fn [ret [k v]] (f ret k v)) init amap)))
(reduce-kv (fn [_ _ _]) nil (array-map 1 2 3 4))
(println "slowpaths" @C)
(reduce-kv (fn [_ _ _]) nil (hash-map 1 2 3 4))
(println "slowpaths" @C)
重现输出
➜ dev /usr/lib/jvm/java-8-openjdk/bin/java -cp $(clojure -Spath) clojure.main kvfastpath.clj
slowpaths 1
slowpaths 2
➜ dev /usr/lib/jvm/java-11-openjdk/bin/java -cp $(clojure -Spath) clojure.main kvfastpath.clj
slowpaths 0
slowpaths 0