diff options
author | Eduardo Julian | 2016-01-05 22:22:54 -0400 |
---|---|---|
committer | Eduardo Julian | 2016-01-05 22:22:54 -0400 |
commit | 3855f395e7cdd8e49086f2d0d82ed231e8896b69 (patch) | |
tree | 173c7b9f3aa5c8f86a44210074634da11b5b9a40 /src/lux/compiler/case.clj | |
parent | c52036b75a692a0def3fedb7f175134d8dfb0f5b (diff) |
- Optimized the new "product" implementation to improve performance & memory consumption.
Diffstat (limited to '')
-rw-r--r-- | src/lux/compiler/case.clj | 16 |
1 files changed, 5 insertions, 11 deletions
diff --git a/src/lux/compiler/case.clj b/src/lux/compiler/case.clj index 1f2188a2f..5e9aacc0f 100644 --- a/src/lux/compiler/case.clj +++ b/src/lux/compiler/case.clj @@ -97,17 +97,12 @@ _ (doto writer (.visitTypeInsn Opcodes/CHECKCAST "[Ljava/lang/Object;") - (.visitInsn Opcodes/DUP) - (.visitLdcInsn (int 2)) - (.visitInsn Opcodes/AALOAD) - (.visitTypeInsn Opcodes/CHECKCAST "[Ljava/lang/Object;") (-> (doto (.visitInsn Opcodes/DUP) (.visitLdcInsn (int idx)) (.visitInsn Opcodes/AALOAD) (compile-match test $next $sub-else) (.visitLabel $sub-else) (.visitInsn Opcodes/POP) - (.visitInsn Opcodes/POP) (.visitJumpInsn Opcodes/GOTO $else) (.visitLabel $next)) (->> (|let [[idx test] idx+member @@ -115,7 +110,6 @@ $sub-else (new Label)]) (doseq [idx+member (->> ?members &/enumerate &/->seq)]))) (.visitInsn Opcodes/POP) - (.visitInsn Opcodes/POP) (.visitJumpInsn Opcodes/GOTO $target))) (&a-case/$VariantTestAC ?tag ?count ?test) @@ -146,17 +140,17 @@ (|let [[_ mappings patterns*] (&/fold (fn [$id+mappings+=matches pattern+body] (|let [[$id mappings =matches] $id+mappings+=matches [pattern body] pattern+body] - (&/T (inc $id) (&/|put $id body mappings) (&/|put $id pattern =matches)))) - (&/T 0 (&/|table) (&/|table)) + (&/T [(inc $id) (&/|put $id body mappings) (&/|put $id pattern =matches)]))) + (&/T [0 (&/|table) (&/|table)]) patterns)] - (&/T mappings (&/|reverse patterns*)))) + (&/T [mappings (&/|reverse patterns*)]))) (defn ^:private compile-pattern-matching [^MethodVisitor writer compile mappings patterns $end] (let [entries (&/|map (fn [?branch+?body] (|let [[?branch ?body] ?branch+?body label (new Label)] - (&/T (&/T ?branch label) - (&/T label ?body)))) + (&/T [(&/T [?branch label]) + (&/T [label ?body])]))) mappings) mappings* (&/|map &/|first entries)] (doto writer |