diff options
author | Eduardo Julian | 2018-08-24 00:19:02 -0400 |
---|---|---|
committer | Eduardo Julian | 2018-08-24 00:19:02 -0400 |
commit | 676fbcc0d6a8962ce9cb83136b2a0d0e9ff1e28e (patch) | |
tree | c1290ac597dbf1385cbb4ad8005a73a4dd0bb3ee /luxc/src | |
parent | 7c52f72aad338a0f14ed173926784373e551be71 (diff) |
Some micro-optimizations.
Diffstat (limited to '')
-rw-r--r-- | luxc/src/lux/analyser/proc/common.clj | 13 | ||||
-rw-r--r-- | luxc/src/lux/compiler/jvm/proc/common.clj | 25 |
2 files changed, 21 insertions, 17 deletions
diff --git a/luxc/src/lux/analyser/proc/common.clj b/luxc/src/lux/analyser/proc/common.clj index 7ce4974f7..fbdf05546 100644 --- a/luxc/src/lux/analyser/proc/common.clj +++ b/luxc/src/lux/analyser/proc/common.clj @@ -239,12 +239,13 @@ =input (&&/analyse-1 analyse &type/Nat ?input) _ (assert! (even? (&/|length ?pairs)) "The number of matches must be even!") =pairs (&/map% (fn [?pair] - (|let [[?pattern ?match] ?pair] - (|case ?pattern - [_ (&/$Text ^String ?pattern-char)] - (|do [=match (&&/analyse-1 analyse exo-type ?match)] - (return (&/T [(int (.charAt ?pattern-char 0)) - =match])))))) + (|let [[[_ (&/$Tuple ?patterns)] ?match] ?pair] + (|do [=match (&&/analyse-1 analyse exo-type ?match)] + (return (&/T [(&/|map (fn [?pattern] + (|let [[_ (&/$Text ^String ?pattern-char)] ?pattern] + (int (.charAt ?pattern-char 0)))) + ?patterns) + =match]))))) (&/|as-pairs ?pairs)) =else (&&/analyse-1 analyse exo-type ?else)] (return (&/|list (&&/|meta exo-type _cursor diff --git a/luxc/src/lux/compiler/jvm/proc/common.clj b/luxc/src/lux/compiler/jvm/proc/common.clj index dafcb64ef..5cff63d86 100644 --- a/luxc/src/lux/compiler/jvm/proc/common.clj +++ b/luxc/src/lux/compiler/jvm/proc/common.clj @@ -374,22 +374,25 @@ (defn ^:private compile-syntax-char-case! [compile ?values ?patterns] (|do [:let [(&/$Cons ?input (&/$Cons [_ (&a/$tuple ?matches)] (&/$Cons ?else (&/$Nil)))) ?values] ^MethodVisitor *writer* &/get-writer - :let [?patterns+?matches* (->> (&/zip2 ?patterns ?matches) - &/->seq - (sort-by &/|first <) - &/->list) - ?patterns* (&/|map &/|first ?patterns+?matches*) - ?matches* (&/|map &/|second ?patterns+?matches*) + :let [pattern-labels (&/|map (fn [_] (new Label)) ?patterns) + matched-patterns (->> (&/zip2 ?patterns pattern-labels) + (&/flat-map (fn [?chars+?label] + (|let [[?chars ?label] ?chars+?label] + (&/|map (fn [?char] + (&/T [?char ?label])) + ?chars)))) + &/->seq + (sort-by &/|first <) + &/->list) end-label (new Label) - else-label (new Label) - pattern-labels (&/|map (fn [_] (new Label)) ?patterns*)] + else-label (new Label)] _ (compile ?input) :let [_ (doto *writer* &&/unwrap-long (.visitInsn Opcodes/L2I) (.visitLookupSwitchInsn else-label - (int-array (&/->seq ?patterns*)) - (into-array (&/->seq pattern-labels))))] + (int-array (&/->seq (&/|map &/|first matched-patterns))) + (into-array (&/->seq (&/|map &/|second matched-patterns)))))] _ (&/map% (fn [?label+?match] (|let [[?label ?match] ?label+?match] (|do [:let [_ (doto *writer* @@ -398,7 +401,7 @@ :let [_ (doto *writer* (.visitJumpInsn Opcodes/GOTO end-label))]] (return nil)))) - (&/zip2 pattern-labels ?matches*)) + (&/zip2 pattern-labels ?matches)) :let [_ (doto *writer* (.visitLabel else-label))] _ (compile ?else) |