mirror of
https://github.com/digital-asset/daml.git
synced 2024-09-20 01:07:18 +03:00
Only walk list once in splitAt (#9275)
* Only walk list once in splitAt No idea if that makes a significant difference anywhere but walking the list twice is definitely not faster. changelog_begin changelog_end * Avoid hardcoded locations in tests changelog_begin changelog_end
This commit is contained in:
parent
46c6701d8e
commit
eb91dcf853
@ -422,7 +422,11 @@ drop n (_ :: xs) = drop (n-1) xs
|
||||
|
||||
-- | Split a list at a given index.
|
||||
splitAt : Int -> [a] -> ([a], [a])
|
||||
splitAt i x = (take i x, drop i x)
|
||||
splitAt _ [] = ([], [])
|
||||
splitAt i ys@(x :: xs)
|
||||
| i <= 0 = ([], ys)
|
||||
| otherwise = case splitAt (i - 1) xs of
|
||||
(a, b) -> (x :: a, b)
|
||||
|
||||
-- | Take elements from a list while the predicate holds.
|
||||
takeWhile : (a -> Bool) -> [a] -> [a]
|
||||
|
@ -269,7 +269,10 @@ abstract class AbstractFuncIT
|
||||
}
|
||||
"traceOrder" should {
|
||||
"emit trace statements in correct order" in {
|
||||
def traceMsg(msg: String) = s"""[DA.Internal.Prelude:540]: "$msg""""
|
||||
val msgRegex = raw"""\[DA.Internal.Prelude:\d+]: "(.*)"""".r
|
||||
def stripLoc(msg: String) = msg match {
|
||||
case msgRegex(msg_) => msg_
|
||||
}
|
||||
for {
|
||||
clients <- participantClients()
|
||||
_ = LogCollector.clear()
|
||||
@ -281,7 +284,7 @@ abstract class AbstractFuncIT
|
||||
} yield {
|
||||
assert(v == SUnit)
|
||||
val logMsgs = LogCollector.events.map(_.getMessage)
|
||||
assert(logMsgs == Seq(traceMsg("abc"), traceMsg("def"), traceMsg("abc"), traceMsg("def")))
|
||||
assert(logMsgs.map(stripLoc(_)) == Seq("abc", "def", "abc", "def"))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user