Skip to content

Conversation

@laanwj
Copy link
Member

@laanwj laanwj commented Jan 10, 2019

Two cleanups in util/strencodings.h:

  • Remove [U](BEGIN|END) macros — The only use of these was in the Merkle tree code with uint256 which has its own begin and end methods which are better.
  • Make ToLower and ToUpper take a char — Unfortunately, std::string elements are (bare) chars. As these are the most likely type to be passed to these functions, make them use char instead of unsigned char. This avoids some casts.

Replace use of `BEGIN` and `END` macros on uint256 with `begin()` and
`end()` methods in the Merkle tree code.
Unfortunately, `std::string` elements are (bare) chars. As these
are the most likely type to be passed to these functions, make them use
char instead of unsigned char. This avoids some casts.
@laanwj laanwj force-pushed the 2018_01_utilstrencodings branch from f29ea07 to 332b3dd Compare January 10, 2019 01:51
@Empact
Copy link
Contributor

Empact commented Jan 10, 2019

utACK 332b3dd - could squash the first two

@jonasschnelli
Copy link
Contributor

utACK 332b3dd

@promag
Copy link
Contributor

promag commented Jan 10, 2019

utACK 332b3dd.

@practicalswift
Copy link
Contributor

utACK 332b3dd

Would be nice to have #15134 merged for extra checking of these types of changes :-)

@sipa
Copy link
Member

sipa commented Jan 10, 2019

utACK

@maflcko maflcko merged commit 332b3dd into bitcoin:master Jan 10, 2019
maflcko pushed a commit that referenced this pull request Jan 10, 2019
332b3dd util: Make ToLower and ToUpper take a char (Wladimir J. van der Laan)
edb5bb3 util: remove unused [U](BEGIN|END) macros (Wladimir J. van der Laan)
7fa238c Replace use of BEGIN and END macros on uint256 (Wladimir J. van der Laan)

Pull request description:

  Two cleanups in `util/strencodings.h`:

  - Remove `[U](BEGIN|END)` macros — The only use of these was in the Merkle tree code with `uint256` which has its own `begin` and `end` methods which are better.
  - Make ToLower and ToUpper take a char — Unfortunately, `std::string` elements are (bare) chars. As these are the most likely type to be passed to these functions, make them use char instead of unsigned char. This avoids some casts.

Tree-SHA512: 96c8292e1b588d3d7fde95c2e98ad4e7eb75e7baab40a8e8e8209d4e8e7a1bd3b6846601d20976be34a9daabefc50cbc23f3b04200af17d0dfc857c4ec42aca7
void Downcase(std::string& str)
{
std::transform(str.begin(), str.end(), str.begin(), [](unsigned char c){return ToLower(c);});
std::transform(str.begin(), str.end(), str.begin(), [](char c){return ToLower(c);});
Copy link
Member Author

Choose a reason for hiding this comment

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

Just realizing that it's passing a silly identity function:

std::transform(str.begin(), str.end(), str.begin(), ToLower);

Anyhow, not going to file a PR for just that, I guess the compiler optimizes this away, maybe someone touching this code in the future can take it into account.

deadalnix pushed a commit to Bitcoin-ABC/bitcoin-abc that referenced this pull request May 29, 2020
Summary:
Replace use of `BEGIN` and `END` macros on uint256 with `begin()` and
`end()` methods in the Merkle tree code.

---

bitcoin/bitcoin@7fa238c

Partial backport of Core [[bitcoin/bitcoin#15139 | PR15139]]

Test Plan:
  ninja check-all

Reviewers: #bitcoin_abc, deadalnix

Reviewed By: #bitcoin_abc, deadalnix

Differential Revision: https://reviews.bitcoinabc.org/D6288
deadalnix pushed a commit to Bitcoin-ABC/bitcoin-abc that referenced this pull request May 29, 2020
Summary:
bitcoin/bitcoin@edb5bb3

---

Partial backport of Core [[bitcoin/bitcoin#15139 | PR15139]]

Test Plan:
  ninja check

Reviewers: #bitcoin_abc, deadalnix

Reviewed By: #bitcoin_abc, deadalnix

Differential Revision: https://reviews.bitcoinabc.org/D6292
deadalnix pushed a commit to Bitcoin-ABC/bitcoin-abc that referenced this pull request Jun 2, 2020
Summary:
Unfortunately, `std::string` elements are (bare) chars. As these
are the most likely type to be passed to these functions, make them use
char instead of unsigned char. This avoids some casts.

bitcoin/bitcoin@332b3dd

---

Depends on D6294

Concludes backport of Core [[bitcoin/bitcoin#15139 | PR15139]]

Test Plan:
  ninja check

Reviewers: #bitcoin_abc, deadalnix

Reviewed By: #bitcoin_abc, deadalnix

Subscribers: deadalnix

Differential Revision: https://reviews.bitcoinabc.org/D6295
ftrader pushed a commit to bitcoin-cash-node/bitcoin-cash-node that referenced this pull request Aug 17, 2020
Summary:
Replace use of `BEGIN` and `END` macros on uint256 with `begin()` and
`end()` methods in the Merkle tree code.

---

bitcoin/bitcoin@7fa238c

Partial backport of Core [[bitcoin/bitcoin#15139 | PR15139]]

Test Plan:
  ninja check-all

Reviewers: #bitcoin_abc, deadalnix

Reviewed By: #bitcoin_abc, deadalnix

Differential Revision: https://reviews.bitcoinabc.org/D6288
UdjinM6 pushed a commit to UdjinM6/dash that referenced this pull request Aug 24, 2021
332b3dd util: Make ToLower and ToUpper take a char (Wladimir J. van der Laan)
edb5bb3 util: remove unused [U](BEGIN|END) macros (Wladimir J. van der Laan)
7fa238c Replace use of BEGIN and END macros on uint256 (Wladimir J. van der Laan)

Pull request description:

  Two cleanups in `util/strencodings.h`:

  - Remove `[U](BEGIN|END)` macros — The only use of these was in the Merkle tree code with `uint256` which has its own `begin` and `end` methods which are better.
  - Make ToLower and ToUpper take a char — Unfortunately, `std::string` elements are (bare) chars. As these are the most likely type to be passed to these functions, make them use char instead of unsigned char. This avoids some casts.

Tree-SHA512: 96c8292e1b588d3d7fde95c2e98ad4e7eb75e7baab40a8e8e8209d4e8e7a1bd3b6846601d20976be34a9daabefc50cbc23f3b04200af17d0dfc857c4ec42aca7
Munkybooty pushed a commit to Munkybooty/dash that referenced this pull request Aug 24, 2021
332b3dd util: Make ToLower and ToUpper take a char (Wladimir J. van der Laan)
edb5bb3 util: remove unused [U](BEGIN|END) macros (Wladimir J. van der Laan)
7fa238c Replace use of BEGIN and END macros on uint256 (Wladimir J. van der Laan)

Pull request description:

  Two cleanups in `util/strencodings.h`:

  - Remove `[U](BEGIN|END)` macros — The only use of these was in the Merkle tree code with `uint256` which has its own `begin` and `end` methods which are better.
  - Make ToLower and ToUpper take a char — Unfortunately, `std::string` elements are (bare) chars. As these are the most likely type to be passed to these functions, make them use char instead of unsigned char. This avoids some casts.

Tree-SHA512: 96c8292e1b588d3d7fde95c2e98ad4e7eb75e7baab40a8e8e8209d4e8e7a1bd3b6846601d20976be34a9daabefc50cbc23f3b04200af17d0dfc857c4ec42aca7
@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.

7 participants