ReplaceAll()
seems enough for all of our purposes.
refactor: Drop boost/algorithm/string/replace.hpp
dependency
#25803
pull
hebasto
wants to merge
2
commits into
bitcoin:master
from
hebasto:220808-replace
changing
4
files
+23 −7
-
hebasto commented at 10:57 am on August 8, 2022: memberA new implementation of the
-
test: Add test case for `ReplaceAll()` function 857526e8cb
-
refactor: Drop `boost/algorithm/string/replace.hpp` dependency fea75ad3ca
-
fanquake added the label Refactoring on Aug 8, 2022
-
Sjors commented at 4:42 pm on August 8, 2022: member
Concept ACK
ReplaceAll()
is currently used for handling-blocknotify
,-walletnotify
,-alertnotify
and escaping slashes in-torpassword
. -
luke-jr commented at 1:59 am on August 10, 2022: memberWhat do we gain from this?
-
Sjors commented at 8:35 am on August 10, 2022: memberAlternatively: reducing the number of Boost includes by 10% :-)
-
fanquake commented at 11:07 am on August 10, 2022: member
ACK
What do we gain from this?
Using the standard library over a third party dependency.
-
adam2k commented at 5:43 pm on August 10, 2022: none
ACK Tested fea75ad3caa29972db32d3ce7e0fe125ec77a0eb
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 totalOn fea75ad3caa29972db32d3ce7e0fe125ec77a0eb make check 276.10s user 22.31s system 48% cpu 10:11.89 total
-
MarcoFalke commented at 5:56 pm on August 10, 2022: memberNot that it matters for our use cases, but I’d suspect that regex is slower than string-replace in a microbench.
-
theStack approved
-
theStack commented at 6:55 pm on August 15, 2022: contributor
Code-review ACK fea75ad3caa29972db32d3ce7e0fe125ec77a0eb
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 commented at 9:33 pm on August 15, 2022: contributorConcept ACK on getting rid of external dependency.
-
luke-jr commented at 11:26 pm on August 15, 2022: memberThe only thing worse than a dependency, is a bundled reimplementation. Especially if the implementation is worse.
-
fanquake merged this on Aug 16, 2022
-
fanquake closed this on Aug 16, 2022
-
hebasto deleted the branch on Aug 16, 2022
-
in src/util/string.cpp:14 in fea75ad3ca
13-void ReplaceAll(std::string& in_out, std::string_view search, std::string_view substitute) 14+void ReplaceAll(std::string& in_out, const std::string& search, const std::string& substitute) 15 { 16- boost::replace_all(in_out, search, substitute); 17+ if (search.empty()) return; 18+ in_out = std::regex_replace(in_out, std::regex(std::move(search)), substitute);
MarcoFalke commented at 8:44 am on August 16, 2022:you can’t move aconst
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
MarcoFalke commented at 12:16 pm on August 19, 2022:sidhujag referenced this in commit c9306ffbbe on Aug 16, 2022Fabcien referenced this in commit c682e1d7f6 on Jun 3, 2023bitcoin locked this on Aug 19, 2023
This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2024-11-21 12:12 UTC
More mirrored repositories can be found on mirror.b10c.me