Skip to content

Commit

Permalink
protoc: use transducer instead of nested map
Browse files Browse the repository at this point in the history
  • Loading branch information
st-cheewah committed Dec 23, 2023
1 parent eda5e65 commit f7f29da
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 8 deletions.
7 changes: 3 additions & 4 deletions src/clojobuf/core.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,9 @@
"Generate codec and malli registries and return them as a tuple."
[paths files & {:keys [auto-malli-registry] :or {auto-malli-registry true}}]
(let [rast (unnest (rc/protoc paths files))
; TODO below is super inefficient, use transducer or other ways
codec_malli_pairs (reduce into [] (map xform-ast (map val rast)))
codec (into {} (map first) codec_malli_pairs)
malli (into {} (map second) codec_malli_pairs)
codec_malli_pairs (transduce (map (comp xform-ast val)) into [] rast)
codec (transduce (map first) into {} codec_malli_pairs)
malli (transduce (map second) into {} codec_malli_pairs)
malli (if auto-malli-registry
(->malli-registry malli)
malli)]
Expand Down
7 changes: 3 additions & 4 deletions src/clojobuf/nodejs.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,9 @@
"Generate codec and malli registries and return them as a tuple."
[paths files & {:keys [auto-malli-registry] :or {auto-malli-registry true}}]
(let [rast (unnest (rc/protoc paths files))
; TODO below is super inefficient, use transducer or other ways
codec_malli_pairs (reduce into [] (map xform-ast (map val rast)))
codec (into {} (map first) codec_malli_pairs)
malli (into {} (map second) codec_malli_pairs)
codec_malli_pairs (transduce (map (comp xform-ast val)) into [] rast)
codec (transduce (map first) into {} codec_malli_pairs)
malli (transduce (map second) into {} codec_malli_pairs)
malli (if auto-malli-registry
(->malli-registry malli)
malli)]
Expand Down

0 comments on commit f7f29da

Please sign in to comment.