Skip to content

Conversation

practicalswift
Copy link
Contributor

Prefer ...

z = std::max(x - y, 0);

... over ...

z = x - y;
if (z < 0)
    z = 0;

... as suggested by @robmcl4.

Please note that the nSinceLastSeen is intentionally skipped since nSinceLastSeen is unused and is being removed as part of #9532.

@practicalswift practicalswift force-pushed the std-max branch 2 times, most recently from 433bb96 to bb35501 Compare January 14, 2017 10:50
nAfterFee = nAmount - nPayFee;
if (nAfterFee < 0)
nAfterFee = 0;
nAfterFee = std::max(nAmount - nPayFee, (int64_t)0);
Copy link
Member

Choose a reason for hiding this comment

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

Imo this is a step back to before #4234

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point! Updated version pushed :-)

src/addrman.cpp Outdated
@@ -55,12 +55,10 @@ double CAddrInfo::GetChance(int64_t nNow) const
double fChance = 1.0;

int64_t nSinceLastSeen = nNow - nTime;
int64_t nSinceLastTry = nNow - nLastTry;
int64_t nSinceLastTry = std::max(nNow - nLastTry, (int64_t)0);
Copy link
Member

Choose a reason for hiding this comment

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

micronit: maybe use std::max<int64_t>(nNow - nLastTry, 0) to avoid a cast?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point! Fixed and pushed! :-)

nAfterFee = nAmount - nPayFee;
if (nAfterFee < 0)
nAfterFee = 0;
nAfterFee = std::max(nAmount - nPayFee, (CAmount)0);
Copy link
Member

Choose a reason for hiding this comment

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

Same here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed and pushed!

@luke-jr
Copy link
Member

luke-jr commented Jan 14, 2017

I think it's actually more readable the longer way in some cases, but don't care strongly. (I would probably think differently if there was an alias called std::at_least or something.)

src/addrman.cpp Outdated
@@ -55,12 +55,10 @@ double CAddrInfo::GetChance(int64_t nNow) const
double fChance = 1.0;

int64_t nSinceLastSeen = nNow - nTime;
int64_t nSinceLastTry = nNow - nLastTry;
int64_t nSinceLastTry = std::max<int64_t>(nNow - nLastTry, 0);

if (nSinceLastSeen < 0)
Copy link
Contributor

@jtimon jtimon Feb 2, 2017

Choose a reason for hiding this comment

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

why not do the same for nSinceLastSeen while you're at it for consistency?
EDIT: Never mind, is being removed in #9532

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@jtimon See the comment in the PR body:

Please note that the nSinceLastSeen is intentionally skipped since nSinceLastSeen is unused and is being removed as part of #9532.

:-)

@jtimon
Copy link
Contributor

jtimon commented Feb 2, 2017

ACK 660b28b modulo nit.

@@ -55,10 +55,9 @@ double
CTxMemPoolEntry::GetPriority(unsigned int currentHeight) const
Copy link
Member

Choose a reason for hiding this comment

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

This is about to get removed as well, so you can drop it here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@MarcoFalke What should be dropped? Sorry, didn't catch that :-)

Do you mean that the changes to src/txmempool.cpp should be excluded from this commit?

Copy link
Member

Choose a reason for hiding this comment

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

Everything that has "priority" in its name is scheduled to be removed, so this function as well.

@practicalswift
Copy link
Contributor Author

@MarcoFalke Fixed and pushed! Looks good? :-)

@jtimon
Copy link
Contributor

jtimon commented Feb 3, 2017

ACK c04f80b

@maflcko
Copy link
Member

maflcko commented Feb 3, 2017 via email

@laanwj
Copy link
Member

laanwj commented Feb 7, 2017

Needs rebase after #9532

@practicalswift
Copy link
Contributor Author

@laanwj Thanks for the ping! Rebased and pushed! :-)

@jtimon
Copy link
Contributor

jtimon commented Feb 8, 2017

ACK a47da4b

@practicalswift
Copy link
Contributor Author

Anything needed before merge? :-)

@paveljanik
Copy link
Contributor

ACK a47da4b

@laanwj laanwj merged commit a47da4b into bitcoin:master Feb 15, 2017
laanwj added a commit that referenced this pull request Feb 15, 2017
… 0) z = 0;

a47da4b Use z = std::max(x - y, 0); instead of z = x - y; if (z < 0) z = 0; (practicalswift)
codablock pushed a commit to codablock/dash that referenced this pull request Jan 23, 2018
…if (z < 0) z = 0;

a47da4b Use z = std::max(x - y, 0); instead of z = x - y; if (z < 0) z = 0; (practicalswift)
andvgal pushed a commit to energicryptocurrency/gen2-energi that referenced this pull request Jan 6, 2019
…if (z < 0) z = 0;

a47da4b Use z = std::max(x - y, 0); instead of z = x - y; if (z < 0) z = 0; (practicalswift)
CryptoCentric pushed a commit to absolute-community/absolute that referenced this pull request Feb 27, 2019
…if (z < 0) z = 0;

a47da4b Use z = std::max(x - y, 0); instead of z = x - y; if (z < 0) z = 0; (practicalswift)
@practicalswift practicalswift deleted the std-max branch April 10, 2021 19:29
@bitcoin bitcoin locked as resolved and limited conversation to collaborators Aug 16, 2022
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