-
Notifications
You must be signed in to change notification settings - Fork 8k
ext/standard: Some more small refactoring #15391
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
Conversation
} else if (c >= 'A' && c <= 'F') { | ||
return c - 'A' + 10; | ||
} | ||
else if (c >= 'a' && c <= 'f') { | ||
} else { | ||
ZEND_ASSERT(c >= 'a' && c <= 'f'); | ||
return c - 'a' + 10; | ||
} | ||
else { | ||
return -1; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm wondering if we should not just use a bitwise operation to make it unconditionally lower/uppercase so that we don't need to do another if
check.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That might be probably more expensive if I understand correct you want to use store (not just load). What you can do is is maybe to get rid of one condition but not sure if it's worth the readability:
if (isdigit(c)) {
return c - '0';
} else if (c >= 'a') {
ZEND_ASSERT(c <= 'f');
return c - 'a' + 10;
} else {
ZEND_ASSERT(c >= 'A' && c <= 'F');
return c - 'A' + 10;
}
} else if (c >= 'A' && c <= 'F') { | ||
return c - 'A' + 10; | ||
} | ||
else if (c >= 'a' && c <= 'f') { | ||
} else { | ||
ZEND_ASSERT(c >= 'a' && c <= 'f'); | ||
return c - 'a' + 10; | ||
} | ||
else { | ||
return -1; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That might be probably more expensive if I understand correct you want to use store (not just load). What you can do is is maybe to get rid of one condition but not sure if it's worth the readability:
if (isdigit(c)) {
return c - '0';
} else if (c >= 'a') {
ZEND_ASSERT(c <= 'f');
return c - 'a' + 10;
} else {
ZEND_ASSERT(c >= 'A' && c <= 'F');
return c - 'A' + 10;
}
We already check, and assume, that the value is hexadecimal
Main objective is to remove the PHP_STR_STR(C)SPN symbols which are only used with this static function
This is not used from a quick search on SourceGraph and this allows us to refactor it
1d542c7
to
74330b9
Compare
No description provided.