From 802c048ec6c9350f0c22e4a1bc241c2cc38fee14 Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Fri, 10 Feb 2017 17:09:54 -0500 Subject: [PATCH] Pull the drop & take into the where clause. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This change, while semantically equivalent, causes `slice` to complete in approximately 1/3rd the time, and allocate only a fraction as much. Maybe ghc can fuse this better or something? I honestly have no idea, but I’ll take it. /cc @github/semantic-code --- src/Source.hs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Source.hs b/src/Source.hs index c7acbe7b2..57e7445bb 100644 --- a/src/Source.hs +++ b/src/Source.hs @@ -56,7 +56,9 @@ fromText = Source -- | Return a Source that contains a slice of the given Source. slice :: Range -> Source -> Source -slice range = Source . Text.take (rangeLength range) . Text.drop (start range) . sourceText +slice range = Source . take . drop . sourceText + where drop = Text.drop (start range) + take = Text.take (rangeLength range) -- | Return a String with the contents of the Source. toString :: Source -> String