Read-only mirrors. Development, issues and pull requests are on GitHub.

summaryrefslogtreecommitdiffhomepage
path: root/src/catch2/internal/catch_run_context.cpp
diff options
context:
space:
mode:
authorMartin Hořeňovský2025-07-21 19:25:48 +0200
committerMartin Hořeňovský2025-07-21 21:50:49 +0200
commit9c5c21df82372b9d266f6b6bc1cf0edd71337109 (patch)
tree5533eb0123303c58decea16d1008b0316fc87095 /src/catch2/internal/catch_run_context.cpp
parent10aef62f21e52e5cd73bf0dc6ac8be35fbc4a798 (diff)
downloadcatch3-9c5c21df82372b9d266f6b6bc1cf0edd71337109.tar.gz
Simplify removal of messages from RunContext
Instead of doing range-based removals, we only erase specific message, because there can never be more than 1 message with the specific ID.
Diffstat (limited to 'src/catch2/internal/catch_run_context.cpp')
-rw-r--r--src/catch2/internal/catch_run_context.cpp16
1 files changed, 10 insertions, 6 deletions
diff --git a/src/catch2/internal/catch_run_context.cpp b/src/catch2/internal/catch_run_context.cpp
index 6991ddcf..118d37f8 100644
--- a/src/catch2/internal/catch_run_context.cpp
+++ b/src/catch2/internal/catch_run_context.cpp
@@ -437,13 +437,17 @@ namespace Catch {
}
void RunContext::popScopedMessage( MessageInfo const& message ) {
+ // Note: On average, it would probably be better to look for the message
+ // backwards. However, we do not expect to have to deal with more
+ // messages than low single digits, so the optimization is tiny,
+ // and we would have to hand-write the loop to avoid terrible
+ // codegen of reverse iterators in debug mode.
m_messages.erase(
- std::remove_if( m_messages.begin(),
- m_messages.end(),
- [id = message.sequence]( MessageInfo const& msg ) {
- return msg.sequence == id;
- } ),
- m_messages.end() );
+ std::find_if( m_messages.begin(),
+ m_messages.end(),
+ [id = message.sequence]( MessageInfo const& msg ) {
+ return msg.sequence == id;
+ } ) );
}
void RunContext::emplaceUnscopedMessage( MessageBuilder&& builder ) {