-
Notifications
You must be signed in to change notification settings - Fork 593
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update DataStorm strings #3015
Update DataStorm strings #3015
Conversation
@@ -71,16 +71,16 @@ namespace DataStormI | |||
{ | |||
public: | |||
Sample( | |||
const std::string& session, | |||
const std::string& origin, | |||
std::string session, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Keep in mind that even if the caller keeps his string (neglects to move it), the performance is identical - the previous code was copying this string.
@@ -706,7 +706,7 @@ namespace DataStorm | |||
SingleKeyReader( | |||
const Topic<Key, Value, UpdateTag>& topic, | |||
const Key& key, | |||
const std::string& name = std::string(), | |||
std::string name = std::string(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The focus of this PR was strings. It's possible other parameters should be by value too.
@@ -15,28 +15,28 @@ namespace DataStormI | |||
|
|||
class TopicI; | |||
|
|||
class TopicFactoryI : public TopicFactory, public std::enable_shared_from_this<TopicFactoryI> | |||
class TopicFactoryI final : public TopicFactory, public std::enable_shared_from_this<TopicFactoryI> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need a more systematic cleanup in a follow-up PR for final / override and similar.
cpp/include/DataStorm/DataStorm.h
Outdated
@@ -1829,6 +1833,7 @@ namespace DataStorm | |||
template<typename Value> | |||
std::function<std::function<bool(const Value&)>(const std::string&)> makeRegexFilter() noexcept | |||
{ | |||
// std::regex_match accepts a const string&. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you mean the std::regex
constructor? We don't pass criteria to regex_match
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here is the full code:
// std::regex_match accepts a const string&.
return [](const std::string& criteria)
{
std::regex expr(criteria);
return [expr](const Value& value)
{
std::ostringstream os;
os << value;
return std::regex_match(os.str(), expr);
};
};
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Value can be anything that defines <<
osstream operator, it doesn't have to be a string.
For the regex constructor can we use 8 https://en.cppreference.com/w/cpp/regex/basic_regex/basic_regex
And do:
return [](std::string criteria)
{
std::regex expr(std::move(criteria));
I think the complication here is this template factory are used for different things and, pass by value might be not supported for all usages.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What I meant with this comment is a typical regex filter function - regex_match - accepts a const string&
and not a string_view
(which in theory it could), and as a result it's ok/reasonable for our makeRegexFilter function to return a function that accepts a const string&
and not a string_view
.
basic_regex does not provide a constructor with string
parameter. I don't see how (8) would work with:
std::regex expr(std::move(criteria));
I think you would still get (6).
In any case, I'll update to comment to refer to the regex constructor.
This PR updates the DataStorm to use
string
(copies) instead ofconst string&
where appropriate.