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

dead code: Remove dead option in HexStr conversion #15573

Merged
merged 1 commit into from
Mar 12, 2019

Conversation

ldm5180
Copy link
Contributor

@ldm5180 ldm5180 commented Mar 10, 2019

Problem:

  • Nothing uses the fspaces argument to HexStr() besides unit
    tests. This argument results in extra complexity and a small
    performance decrease within the function.

Solution:

  • Remove unused fspaces option.
  • Remove associated unit tests.

@Empact
Copy link
Member

Empact commented Mar 10, 2019

I wouldn’t call the performance difference worthwhile, but I’m all for removing dead code.

Copy link
Member

@promag promag left a comment

Choose a reason for hiding this comment

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

Concept ACK, if it's not used then it can be removed.

I don't think the performance gain justifies this change. Anyway, I think the following is enough:

--- a/src/util/strencodings.h
+++ b/src/util/strencodings.h
@@ -121,17 +121,15 @@ NODISCARD bool ParseUInt64(const std::string& str, uint64_t *out);
 NODISCARD bool ParseDouble(const std::string& str, double *out);

 template<typename T>
-std::string HexStr(const T itbegin, const T itend, bool fSpaces=false)
+std::string HexStr(const T itbegin, const T itend)
 {
     std::string rv;
     static const char hexmap[16] = { '0', '1', '2', '3', '4', '5', '6', '7',
                                      '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' };
-    rv.reserve((itend-itbegin)*3);
+    rv.reserve((itend-itbegin) * 2);
     for(T it = itbegin; it < itend; ++it)
     {
         unsigned char val = (unsigned char)(*it);
-        if(fSpaces && it != itbegin)
-            rv.push_back(' ');
         rv.push_back(hexmap[val>>4]);
         rv.push_back(hexmap[val&15]);
     }
@@ -140,9 +138,9 @@ std::string HexStr(const T itbegin, const T itend, bool fSpaces=false)
 }

 template<typename T>
-inline std::string HexStr(const T& vch, bool fSpaces=false)
+inline std::string HexStr(const T& vch)
 {
-    return HexStr(vch.begin(), vch.end(), fSpaces);
+    return HexStr(vch.begin(), vch.end());
 }

 /**

@sipa
Copy link
Member

sipa commented Mar 10, 2019

HexStr does not in any way affect the Base58 benchmarks, I think?

@ldm5180
Copy link
Contributor Author

ldm5180 commented Mar 11, 2019

Limited change to only removing dead code and updated PR details.

@DrahtBot
Copy link
Contributor

The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

Conflicts

Reviewers, this pull request conflicts with the following ones:

  • #15576 (constexpr: Increase constexpr usage in strencodings by ldm5180)

If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first.

Problem:
- Nothing uses the `fspaces` argument to `HexStr()` besides unit
  tests. This argument results in extra complexity and a small
  performance decrease within the function for branch evalulation.

Solution:
- Remove unused `fspaces` option.
@Empact
Copy link
Member

Empact commented Mar 11, 2019

utACK 56f1d28

@practicalswift
Copy link
Contributor

utACK 56f1d28

-42 lines: very nice! Thanks for removing this cruft.

@maflcko
Copy link
Member

maflcko commented Mar 11, 2019

utACK 56f1d28

@promag
Copy link
Member

promag commented Mar 11, 2019

utACK 56f1d28.

HexStr does not in any way affect the Base58 benchmarks, I think?

@ldm5180 why did you use those benchs in the first place?

@laanwj laanwj merged commit 56f1d28 into bitcoin:master Mar 12, 2019
laanwj added a commit that referenced this pull request Mar 12, 2019
56f1d28 dead code: Remove dead option in HexStr conversion (Lenny Maiorani)

Pull request description:

  Problem:
  - Nothing uses the `fspaces` argument to `HexStr()` besides unit
    tests. This argument results in extra complexity and a small
    performance decrease within the function.

  Solution:
  - Remove unused `fspaces` option.
  - Remove associated unit tests.

Tree-SHA512: 33d00ce354bbc62a77232fa301cdef0a9ed2c5a09e792bc40e9620c2f2f88636e322a38c76b81d10d12a1768dd1b3b2b9cf180f7e33daef9b4f27afed68ccf70
jasonbcox pushed a commit to Bitcoin-ABC/bitcoin-abc that referenced this pull request Oct 3, 2020
Summary:
Problem:
- Nothing uses the `fspaces` argument to `HexStr()` besides unit
  tests. This argument results in extra complexity and a small
  performance decrease within the function for branch evalulation.

Solution:
- Remove unused `fspaces` option.

Backport of Core [[bitcoin/bitcoin#15573 | PR15573]]

Test Plan:
`grep -r 'HexStr([^,]*,[^,]*,' src/`
`ninja all check-all`

Reviewers: O1 Bitcoin ABC, #bitcoin_abc, deadalnix

Reviewed By: O1 Bitcoin ABC, #bitcoin_abc, deadalnix

Subscribers: deadalnix

Differential Revision: https://reviews.bitcoinabc.org/D7738
random-zebra added a commit to PIVX-Project/PIVX that referenced this pull request Aug 16, 2021
d4408cd Make HexStr() take a Span (furszy)
4c755ec dead code: Remove dead option in HexStr conversion. (Lenny Maiorani)

Pull request description:

  Follow up to #2470. Only the last two commits are from this work.

  Make `HexStr` take a span of bytes, instead of an awkward pair of templated iterators. Simplifying most of the uses.

  Adaptation of bitcoin#19660 and bitcoin#15573.

ACKs for top commit:
  random-zebra:
    utACK d4408cd

Tree-SHA512: 541f80e1af9abea2d662e5fc31fc4d5b4057ff93eefeba5632c6ddca391f3b148c8d819a56802720c3932c3c2afb69ddd1efb4890a59ecf1bf5afd6686cd5a67
@bitcoin bitcoin locked as resolved and limited conversation to collaborators Dec 16, 2021
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.

None yet

9 participants