Skip to content

Conversation

@hebasto
Copy link
Member

@hebasto hebasto commented Aug 8, 2022

A new implementation of the ReplaceAll() seems enough for all of our purposes.

@Sjors
Copy link
Member

Sjors commented Aug 8, 2022

Concept ACK

ReplaceAll() is currently used for handling -blocknotify, -walletnotify,-alertnotify and escaping slashes in -torpassword.

@luke-jr
Copy link
Member

luke-jr commented Aug 10, 2022

What do we gain from this?

@hebasto
Copy link
Member Author

hebasto commented Aug 10, 2022

@luke-jr

What do we gain from this?

As the title said:

Drop boost/algorithm/string/replace.hpp dependency

@Sjors
Copy link
Member

Sjors commented Aug 10, 2022

Alternatively: reducing the number of Boost includes by 10% :-)

@fanquake
Copy link
Member

ACK

What do we gain from this?

Using the standard library over a third party dependency.

@adam2k
Copy link

adam2k commented Aug 10, 2022

ACK Tested fea75ad

This is anecdotal, but on an M1 MacBook Pro 14" 2021 (8 core CPU) there is a slight performance boost (no pun intended 😅)

On master
make check 289.85s user 24.91s system 55% cpu 9:24.87 total

On fea75ad
make check 276.10s user 22.31s system 48% cpu 10:11.89 total

@maflcko
Copy link
Member

maflcko commented Aug 10, 2022

Not that it matters for our use cases, but I'd suspect that regex is slower than string-replace in a microbench.

Copy link
Contributor

@theStack theStack left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code-review ACK fea75ad

The idea of using regexes for the task of a simple replace-all substitution seemed excessive to me at first, but IMHO it's worth it to get rid of another Boost dependency.

nit: Untested, but IIUC, passing the flag match_not_null would be an alternative to the manual check whether the search string is empty? https://en.cppreference.com/w/cpp/regex/match_flag_type

@kristapsk
Copy link
Contributor

Concept ACK on getting rid of external dependency.

@luke-jr
Copy link
Member

luke-jr commented Aug 15, 2022

The only thing worse than a dependency, is a bundled reimplementation. Especially if the implementation is worse.

@fanquake fanquake merged commit cf39913 into bitcoin:master Aug 16, 2022
@hebasto hebasto deleted the 220808-replace branch August 16, 2022 08:35
{
boost::replace_all(in_out, search, substitute);
if (search.empty()) return;
in_out = std::regex_replace(in_out, std::regex(std::move(search)), substitute);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can't move a const value. This is a no-op. Even if it wasn't const, this would still be a no-op as there is no constructor taking a non-const ref

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sidhujag pushed a commit to syscoin/syscoin that referenced this pull request Aug 16, 2022
Fabcien pushed a commit to Bitcoin-ABC/bitcoin-abc that referenced this pull request Jun 3, 2023
Summary:
> test: Add test case for `ReplaceAll()` function

> refactor: Drop `boost/algorithm/string/replace.hpp` dependency

This is a backport of [[bitcoin/bitcoin#25803 | core#25803]]
with a `std::move` removed change (see comment by MarcoFalke bitcoin/bitcoin@fea75ad#r946498588)

Test Plan: `ninja all check-all`

Reviewers: #bitcoin_abc, Fabien

Reviewed By: #bitcoin_abc, Fabien

Differential Revision: https://reviews.bitcoinabc.org/D13968
@bitcoin bitcoin locked and limited conversation to collaborators Aug 19, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants