Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better performance for anonymous schematized functions, via lazy checker creation #305

Merged
merged 1 commit into from
Dec 4, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
## 1.0.4
* Update generators, bump minimum version of test.check to 0.9.0. Generators will only work under Clojure 1.7.0+.
* Better performance for anonymous schematized functions, via lazy checker creation

## 1.0.3
* Fix warning about overriding `atom` under Clojure 1.7
Expand Down
12 changes: 7 additions & 5 deletions src/clj/schema/macros.clj
Original file line number Diff line number Diff line change
Expand Up @@ -211,8 +211,8 @@
compile-validation (compile-fn-validation? env fn-name)]
{:schema-binding [input-schema-sym (input-schema-form regular-args rest-arg)]
:more-bindings (when compile-validation
[input-checker-sym `(schema.core/checker ~input-schema-sym)
output-checker-sym `(schema.core/checker ~output-schema-sym)])
[input-checker-sym `(delay (schema.core/checker ~input-schema-sym))
output-checker-sym `(delay (schema.core/checker ~output-schema-sym))])
:arglist bind
:raw-arglist original-arglist
:arity-form (if compile-validation
Expand All @@ -230,15 +230,15 @@
(let [args# ~(if rest-arg
`(list* ~@bind-syms ~rest-sym)
bind-syms)]
(when-let [error# (~input-checker-sym args#)]
(when-let [error# (@~input-checker-sym args#)]
(error! (utils/format* "Input to %s does not match schema: %s"
'~fn-name (pr-str error#))
{:schema ~input-schema-sym :value args# :error error#}))))
(let [o# (loop ~(into (vec (interleave (map #(with-meta % {}) bind) bind-syms))
(when rest-arg [rest-arg rest-sym]))
~@(apply-prepost-conditions body))]
(when validate#
(when-let [error# (~output-checker-sym o#)]
(when-let [error# (@~output-checker-sym o#)]
(error! (utils/format* "Output of %s does not match schema: %s"
'~fn-name (pr-str error#))
{:schema ~output-schema-sym :value o# :error error#})))
Expand Down Expand Up @@ -270,7 +270,9 @@
(mapcat :more-bindings processed-arities)))
:arglists (map :arglist processed-arities)
:raw-arglists (map :raw-arglist processed-arities)
:schema-form `(schema.core/make-fn-schema ~output-schema-sym ~(mapv first schema-bindings))
:schema-form (if (= 1 (count processed-arities))
`(schema.core/->FnSchema ~output-schema-sym ~[(ffirst schema-bindings)])
`(schema.core/make-fn-schema ~output-schema-sym ~(mapv first schema-bindings)))
:fn-body fn-forms}))

(defn parse-arity-spec
Expand Down