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:
parent
041541e466
commit
4326f88c26
@ -48,6 +48,7 @@ module Hledger.Data.Posting (
|
|||||||
where
|
where
|
||||||
import Data.List
|
import Data.List
|
||||||
import Data.Maybe
|
import Data.Maybe
|
||||||
|
import Data.MemoUgly (memo)
|
||||||
import Data.Ord
|
import Data.Ord
|
||||||
import Data.Time.Calendar
|
import Data.Time.Calendar
|
||||||
import Safe
|
import Safe
|
||||||
@ -238,7 +239,7 @@ aliasReplace :: AccountAlias -> AccountName -> AccountName
|
|||||||
aliasReplace (BasicAlias old new) a
|
aliasReplace (BasicAlias old new) a
|
||||||
| old `isAccountNamePrefixOf` a || old == a = new ++ drop (length old) a
|
| old `isAccountNamePrefixOf` a || old == a = new ++ drop (length old) a
|
||||||
| otherwise = 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 [
|
tests_Hledger_Data_Posting = TestList [
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user