Skip to content
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

Merged
merged 8 commits into from
Oct 31, 2024

Conversation

bernardnormier
Copy link
Member

This PR updates the DataStorm to use string (copies) instead of const string& where appropriate.

@@ -71,16 +71,16 @@ namespace DataStormI
{
public:
Sample(
const std::string& session,
const std::string& origin,
std::string session,
Copy link
Member Author

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(),
Copy link
Member Author

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>
Copy link
Member Author

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.

@@ -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&.
Copy link
Member

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

Copy link
Member Author

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);
            };
        };

Copy link
Member

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.

Copy link
Member Author

@bernardnormier bernardnormier Oct 30, 2024

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.

@bernardnormier bernardnormier merged commit 8bc1478 into zeroc-ice:main Oct 31, 2024
18 checks passed
InsertCreativityHere pushed a commit to InsertCreativityHere/compiler-comparison that referenced this pull request Jan 1, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants