Commit ce9c1236 authored by Camil Staps's avatar Camil Staps 🐧

Optimise concatenations of literals

parent bbaa312a
......@@ -16,7 +16,7 @@ import Data.List
import Data.Maybe
import Data.Tuple
import Regex
import Regex => qualified Concat
import Regex.Util
instance zero String where zero = ""
......@@ -31,6 +31,14 @@ where
instance toRegexInput [Char] where toRegexInput cs = cs
instance toRegexInput String where toRegexInput s = [c \\ c <-: s]
Concat rs = 'Regex'.Concat $ concat rs
where
concat [r=:(Literal _):rs] = [Literal $ flatten [l \\ Literal l <- [r:lits]]:concat rest]
where
(lits,rest) = span (\r -> r=:(Literal _)) rs
concat [r:rs] = [r:concat rs]
concat [] = []
regex :: a -> Regex | toRegexInput a
regex s = fromOk $ compile s
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment