Fix list append complexity issue
This commit is contained in:
parent
eeb0c7981d
commit
569d8ccc08
1 changed files with 7 additions and 3 deletions
|
@ -807,9 +807,13 @@ mergeUpdateResults
|
|||
(failed1 || failed2)
|
||||
(nMatched1 + nMatched2)
|
||||
((liftM2 (+)) nModified1 nModified2)
|
||||
(upserted1 ++ upserted2)
|
||||
(writeErrors1 ++ writeErrors2) -- TODO this should be rewritten with IO containers. Otherwise its N^2 complexity.
|
||||
(writeConcernErrors1 ++ writeConcernErrors2)
|
||||
-- This function is used in foldl1' function. The first argument is the accumulator.
|
||||
-- The list in the accumulator is usually longer than the subsequent value which goes in the second argument.
|
||||
-- So, changing the order of list concatenation allows us to keep linear complexity of the
|
||||
-- whole list accumulation process.
|
||||
(upserted2 ++ upserted1)
|
||||
(writeErrors2 ++ writeErrors1)
|
||||
(writeConcernErrors2 ++ writeConcernErrors1)
|
||||
)
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue