From e983ea255188a4dbba36d68fbfc5fb8692c56e91 Mon Sep 17 00:00:00 2001 From: Pepe Iborra Date: Sun, 19 Sep 2021 20:17:53 +0200 Subject: [PATCH] Add INLINABLE pragmas Thanks for your excellent library. We use it for completions in Ghcide / Haskell Language Server Adding these pragmas allows GHC to specialise the function at call sites removing the cost of the TexttualMonoid virtual dispatches. This reduces allocations by 66% and time by up to 50%. --- src/Text/Fuzzy.hs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/Text/Fuzzy.hs b/src/Text/Fuzzy.hs index ff7ad5f..ecd1f8c 100644 --- a/src/Text/Fuzzy.hs +++ b/src/Text/Fuzzy.hs @@ -35,6 +35,7 @@ data (T.TextualMonoid s) => Fuzzy t s = -- >>> match "hsk" ("Haskell",1995) "<" ">" fst False -- Just ("aell",5) -- +{-# INLINABLE match #-} match :: (T.TextualMonoid s) => s -- ^ Pattern. -> t -- ^ The value containing the text to search in. @@ -70,6 +71,7 @@ match pattern t pre post extract caseSensitive = -- -- >>> filter "ML" [("Standard ML", 1990),("OCaml",1996),("Scala",2003)] "<" ">" fst False -- [Fuzzy {original = ("Standard ML",1990), rendered = "standard ", score = 4},Fuzzy {original = ("OCaml",1996), rendered = "oca", score = 4}] +{-# INLINABLE filter #-} filter :: (T.TextualMonoid s) => s -- ^ Pattern. -> [t] -- ^ The list of values containing the text to search in. @@ -88,6 +90,7 @@ filter pattern ts pre post extract caseSen = -- -- >>> simpleFilter "vm" ["vim", "emacs", "virtual machine"] -- ["vim","virtual machine"] +{-# INLINABLE simpleFilter #-} simpleFilter :: (T.TextualMonoid s) => s -- ^ Pattern to look for. -> [s] -- ^ List of texts to check.