[Haskell-cafe] Data.Text performance problem
Petr Prokhorenkov
prokhorenkov at gmail.com
Sun Sep 12 15:23:50 EDT 2010
I experienced a following problem while dealing with some text processing.
I have a text and want to get the same text with parts enclosed into {} or
[] stripped away. Substituting them with a ' ' would also work.
Here is the code I wrote (T is Data.Text):
stripBrackets :: T.Text -> T.Text
stripBrackets text = snd $ T.mapAccumL f 0 text where
f depth c = let
depth' = depth + d' c
c' | depth > 0 || depth' > 0 = ' '
| otherwise = c
in
(depth', c')
d' '{' = 1
d' '[' = 1
d' '}' = -1
d' ']' = -1
d' _ = 0
The only problem is that it takes about a minute to complete on 3GHz+
processor when text is a 30k chars long.
Any ideas how to improve this code?
--
Regards, Petr
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20100912/cb4ac3c7/attachment.html
More information about the Haskell-Cafe
mailing list