Skip to content

Commit

Permalink
C++ 101: Inline methods should be defined in the header.
Browse files Browse the repository at this point in the history
  • Loading branch information
kirkrodrigues committed Sep 17, 2023
1 parent 1c920b4 commit aa1d327
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 18 deletions.
17 changes: 0 additions & 17 deletions components/core/src/ir/parsing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,23 +23,6 @@ bool is_variable_placeholder(char c) {
|| (enum_to_underlying_type(VariablePlaceholder::Float) == c);
}

// NOTE: `inline` improves performance by 1-2%
inline bool could_be_multi_digit_hex_value(string_view str) {
if (str.length() < 2) {
return false;
}

// NOTE: This is 1-2% faster than using std::all_of with the opposite
// condition
for (auto c : str) {
if (!(('a' <= c && c <= 'f') || ('A' <= c && c <= 'F') || ('0' <= c && c <= '9'))) {
return false;
}
}

return true;
}

bool is_var(std::string_view value) {
size_t begin_pos = 0;
size_t end_pos = 0;
Expand Down
17 changes: 16 additions & 1 deletion components/core/src/ir/parsing.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,25 @@ bool is_delim(signed char c);
bool is_variable_placeholder(char c);

/**
* NOTE: This method is marked inline for a 1-2% performance improvement
* @param str
* @return Whether the given string could be a multi-digit hex value
*/
bool could_be_multi_digit_hex_value(std::string_view str);
inline bool could_be_multi_digit_hex_value(std::string_view str) {
if (str.length() < 2) {
return false;
}

// NOTE: This is 1-2% faster than using std::all_of with the opposite
// condition
for (auto c : str) {
if (!(('a' <= c && c <= 'f') || ('A' <= c && c <= 'F') || ('0' <= c && c <= '9'))) {
return false;
}
}

return true;
}

/**
* @param value
Expand Down

0 comments on commit aa1d327

Please sign in to comment.