We still keep the error check in the function, but hide it in an outlined function inside a .cpp file, to promote inlining of the retrieval part. In the future, we should explore two things 1) Skipping over the context retrieval here, allowing direct access. I currently do not see a way to do this while keeping the "greppability" of mutable vs immutable accesses that is there now, but it would help a lot when inlining is not enabled. 2) Removing the error check, to make the function trivially inlinable, and without branches. **runtime difference** | --------- | Debug | Release | |:----------|------:|--------:| | Slow path | 0.98 | 1.07 | | Fast path | 1.04 | 1.08 | We lost bit of performance on the assertion slow path in debug mode, but together with the previous commit, it comes out at net zero. For other combinations, we see 5-10% perf improvement across the two commits.
48 lines
1.3 KiB
C++
48 lines
1.3 KiB
C++
|
|
// Copyright Catch2 Authors
|
|
// Distributed under the Boost Software License, Version 1.0.
|
|
// (See accompanying file LICENSE.txt or copy at
|
|
// https://www.boost.org/LICENSE_1_0.txt)
|
|
|
|
// SPDX-License-Identifier: BSL-1.0
|
|
#ifndef CATCH_CONTEXT_HPP_INCLUDED
|
|
#define CATCH_CONTEXT_HPP_INCLUDED
|
|
|
|
#include <catch2/internal/catch_compiler_capabilities.hpp>
|
|
|
|
namespace Catch {
|
|
|
|
class IResultCapture;
|
|
class IConfig;
|
|
|
|
class Context {
|
|
IConfig const* m_config = nullptr;
|
|
IResultCapture* m_resultCapture = nullptr;
|
|
|
|
CATCH_EXPORT static Context currentContext;
|
|
friend Context& getCurrentMutableContext();
|
|
friend Context const& getCurrentContext();
|
|
|
|
public:
|
|
constexpr IResultCapture* getResultCapture() const {
|
|
return m_resultCapture;
|
|
}
|
|
constexpr IConfig const* getConfig() const { return m_config; }
|
|
constexpr void setResultCapture( IResultCapture* resultCapture ) {
|
|
m_resultCapture = resultCapture;
|
|
}
|
|
constexpr void setConfig( IConfig const* config ) { m_config = config; }
|
|
};
|
|
|
|
Context& getCurrentMutableContext();
|
|
|
|
inline Context const& getCurrentContext() {
|
|
return Context::currentContext;
|
|
}
|
|
|
|
class SimplePcg32;
|
|
SimplePcg32& sharedRng();
|
|
}
|
|
|
|
#endif // CATCH_CONTEXT_HPP_INCLUDED
|