From 8f5f4a2cc4767f56a108b1c0bc11ecb8fd72987b Mon Sep 17 00:00:00 2001 From: Joshua Suskalo Date: Sun, 10 Oct 2021 11:55:06 -0500 Subject: [PATCH] Add multimethod implementations for `primitive-type` This should improve performance --- src/clj/coffi/mem.clj | 41 ++++++++++++++++++++++++++++++++++++++--- 1 file changed, 38 insertions(+), 3 deletions(-) diff --git a/src/clj/coffi/mem.clj b/src/clj/coffi/mem.clj index 6418b35..2cf1bd9 100644 --- a/src/clj/coffi/mem.clj +++ b/src/clj/coffi/mem.clj @@ -230,15 +230,50 @@ Returns nil for any type which does not have a primitive representation." type-dispatch) -;; TODO(Joshua): For performance, turn this into a bunch of specific defmethods (defmethod primitive-type :default - [type] - (primitive-types type)) + [_type] + nil) + +(defmethod primitive-type ::byte + [_type] + ::byte) + +(defmethod primitive-type ::short + [_type] + ::short) + +(defmethod primitive-type ::int + [_type] + ::int) + +(defmethod primitive-type ::long + [_type] + ::long) + +(defmethod primitive-type ::long-long + [_type] + ::long-long) + +(defmethod primitive-type ::char + [_type] + ::char) + +(defmethod primitive-type ::float + [_type] + ::float) + +(defmethod primitive-type ::double + [_type] + ::double) (defmethod primitive-type ::pointer [_type] ::pointer) +(defmethod primitive-type ::void + [_type] + ::void) + (def c-prim-layout "Map of primitive type names to the [[CLinker]] types for a method handle." {::byte CLinker/C_CHAR