From 8e5f01c6fbc5c6f350899b8f7bb7a4cfb86a8eaa Mon Sep 17 00:00:00 2001 From: Mikolaj Konarski Date: Fri, 19 Dec 2025 10:17:18 +0100 Subject: Improve the implemenetation of fromSNat' leading to 6% lower allocation in Det.hs primal test. --- src/Data/Array/Nested/Mixed/Shape.hs | 1 + src/Data/Array/Nested/Types.hs | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) (limited to 'src/Data') diff --git a/src/Data/Array/Nested/Mixed/Shape.hs b/src/Data/Array/Nested/Mixed/Shape.hs index c707f18..302a0fb 100644 --- a/src/Data/Array/Nested/Mixed/Shape.hs +++ b/src/Data/Array/Nested/Mixed/Shape.hs @@ -332,6 +332,7 @@ fromSMayNat :: (n ~ Nothing => i -> r) fromSMayNat f _ (SUnknown i) = f i fromSMayNat _ g (SKnown s) = g s +{-# INLINE fromSMayNat' #-} fromSMayNat' :: SMayNat Int n -> Int fromSMayNat' = fromSMayNat id fromSNat' diff --git a/src/Data/Array/Nested/Types.hs b/src/Data/Array/Nested/Types.hs index 5b084e9..8bb5b85 100644 --- a/src/Data/Array/Nested/Types.hs +++ b/src/Data/Array/Nested/Types.hs @@ -46,7 +46,6 @@ import GHC.TypeLits import GHC.TypeNats qualified as TN import Unsafe.Coerce qualified - -- Reasoning helpers subst1 :: forall f a b. a :~: b -> f a :~: f b @@ -59,8 +58,9 @@ subst2 Refl = Refl data Dict c a where Dict :: c a => Dict c a +{-# INLINE fromSNat' #-} fromSNat' :: SNat n -> Int -fromSNat' = fromIntegral . fromSNat +fromSNat' = fromEnum . TN.fromSNat sameNat' :: SNat n -> SNat m -> Maybe (n :~: m) sameNat' n@SNat m@SNat = sameNat n m -- cgit v1.2.3-70-g09d2