Allocate less in lookupRegexp

Summary:
Contrary to my intuitions this part is the lion share
of allocations in `lookupRegexp`. I'd have expected `Text`
operations to dwarf it.

It's a bit doubious that we build such big lists that it
matters, perhaps in the future we can explore limiting the
number of matches considered.

Reviewed By: patapizza

Differential Revision: D4745711

fbshipit-source-id: ebdc1aa
This commit is contained in:
Bartosz Nitka 2017-03-21 09:02:33 -07:00 committed by Facebook Github Bot
parent 56a039eef1
commit b108ab260f

View File

@ -82,9 +82,9 @@ lookupRegex regex position Document { rawInput = s } = nodes
where
ss = Text.drop position s
(nodes, _, _) = L.foldl' f ([], ss, position) $ match regex ss
f res [] = res
f res ("":_) = res
f (nodes, s, offset) (text:group) = (nodes ++ [node], s', newOffset)
f (nodes, s, offset) [] = (reverse nodes, s, offset)
f (nodes, s, offset) ("":_) = (reverse nodes, s, offset)
f (nodes, s, offset) (text:group) = (node:nodes, s', newOffset)
where
(x,xs) = Text.breakOn text s
m = offset + Text.length x