From 676fbcc0d6a8962ce9cb83136b2a0d0e9ff1e28e Mon Sep 17 00:00:00 2001 From: Eduardo Julian Date: Fri, 24 Aug 2018 00:19:02 -0400 Subject: Some micro-optimizations. --- luxc/src/lux/analyser/proc/common.clj | 13 +++++++------ luxc/src/lux/compiler/jvm/proc/common.clj | 25 ++++++++++++++----------- 2 files changed, 21 insertions(+), 17 deletions(-) (limited to 'luxc/src') 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) -- cgit v1.2.3