In case the condition is false, every character is checked first. This operation is not necessary.
If you call the method with a truncated hex string, you will loose performance. The last check will be done, so is better to do it the first one
In case the condition is false, every character is checked first. This operation is not necessary.
If you call the method with a truncated hex string, you will loose performance. The last check will be done, so is better to do it the first one
58 | @@ -59,12 +59,13 @@ signed char HexDigit(char c) 59 | 60 | bool IsHex(const std::string& str) 61 | { 62 | + if (str.size() <= 0 || str.size()%2 != 0) return false;
Choose your favorite:
if (str.size() == 0 || str.size()%2 != 0) return false;
Please fix your commit messages and remove the merge commit.
As this is an optimization, please also provide benchmarks.
This change supposedly optimizes the false case, I don't think it matters.
In the case of false, we check every character first, not needed
Small optimization for IsHex method [size==0]
Is there any user-visible (or, network-visible) behavior that this would speed up?
Thank you for your first contribution, but we're kind of strict in this project as to requiring a strong rationale for every change. It takes effort to review a change, and there's always a risk.
58 | @@ -59,12 +59,13 @@ signed char HexDigit(char c) 59 | 60 | bool IsHex(const std::string& str) 61 | { 62 | + if (str.size() == 0 || str.size()%2 != 0) return false;
Please add spaces around the modulus operator.
Before was like this
Closing this, sorry, there is no agreement to do this