1
1
mirror of https://github.com/github/semantic.git synced 2024-12-22 22:31:36 +03:00

Pull the drop & take into the where clause.

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
This commit is contained in:
Rob Rix 2017-02-10 17:09:54 -05:00
parent 2bfc2d91c8
commit 802c048ec6

View File

@ -56,7 +56,9 @@ fromText = Source
-- | Return a Source that contains a slice of the given Source. -- | Return a Source that contains a slice of the given Source.
slice :: Range -> Source -> 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. -- | Return a String with the contents of the Source.
toString :: Source -> String toString :: Source -> String