Skip to content

Commit fdd0376

Browse files
authored
Merge pull request #41 from lf-lang/string-view
Optimization: use std::string_view in validation functions
2 parents 3a38f9c + ab4a66d commit fdd0376

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

include/reactor-cpp/assert.hh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,10 @@ using EnvPhase = Environment::Phase;
3838

3939
class ValidationError : public std::runtime_error {
4040
private:
41-
static auto build_message(const std::string& msg) noexcept -> std::string;
41+
static auto build_message(std::string_view msg) noexcept -> std::string;
4242

4343
public:
44-
explicit ValidationError(const std::string& msg)
44+
explicit ValidationError(const std::string_view msg)
4545
: std::runtime_error(build_message(msg)) {}
4646
};
4747

@@ -56,7 +56,7 @@ inline void print_debug_backtrace() {
5656
}
5757
#endif
5858

59-
constexpr inline void validate([[maybe_unused]] bool condition, [[maybe_unused]] const std::string& message) {
59+
constexpr inline void validate([[maybe_unused]] bool condition, [[maybe_unused]] const std::string_view message) {
6060
if constexpr (runtime_validation) { // NOLINT
6161
if (!condition) {
6262
#ifdef __linux__

lib/assert.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
namespace reactor {
1212

13-
auto ValidationError::build_message(const std::string& msg) noexcept -> std::string {
13+
auto ValidationError::build_message(const std::string_view msg) noexcept -> std::string {
1414
std::stringstream string_stream;
1515
string_stream << "Validation Error! \"" << msg << "\"";
1616
return string_stream.str();

0 commit comments

Comments
 (0)