lib: memoise aliasReplace for fast regex aliases (#244)

Roughly speaking, the time to apply regular expression account aliases
was O(aliases x transactions), and should now be O(aliases x accounts).
Also, the constant factor was reduced a lot by the recent commit
memoising toRegex. So now, regex aliases should be "free" like simple
aliases - use as many as you want, the slowdown shouldn't be noticeable.
This commit is contained in:
Simon Michael 2015-09-26 15:45:44 -10:00
parent 041541e466
commit 4326f88c26

View File

@ -48,6 +48,7 @@ module Hledger.Data.Posting (
where
import Data.List
import Data.Maybe
import Data.MemoUgly (memo)
import Data.Ord
import Data.Time.Calendar
import Safe
@ -238,7 +239,7 @@ aliasReplace :: AccountAlias -> AccountName -> AccountName
aliasReplace (BasicAlias old new) a
| old `isAccountNamePrefixOf` a || old == a = new ++ drop (length old) a
| otherwise = a
aliasReplace (RegexAlias re repl) a = regexReplaceCI re repl a
aliasReplace (RegexAlias re repl) a = regexReplaceCIMemo re repl a
tests_Hledger_Data_Posting = TestList [