mirror of
https://github.com/facebook/duckling.git
synced 2024-11-29 01:03:44 +03:00
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:
parent
56a039eef1
commit
b108ab260f
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user