Skip to content

Refactor std string extension #8196

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

Merged
merged 3 commits into from
Apr 23, 2022
Merged

Conversation

Girgias
Copy link
Member

@Girgias Girgias commented Mar 13, 2022

Mainly using more appropriate types, early returns, and moving the happy path to the primary scope

if (found) {
RETURN_LONG(found - ZSTR_VAL(haystack));
} else {
if (!found) {
Copy link
Member

@iluuu1994 iluuu1994 Mar 14, 2022

Choose a reason for hiding this comment

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

This seems like personal preference, are there any code guidelines where the preferred style is specified?

This moves the happy path below the more uncommon failure path which in theory would cause a pipeline stall. That's probably a non-issue with today's branch prediction. Maybe someone with more processor knowledge could answer that one.

(You could of course also just add UNEXPECTED())

Copy link
Member Author

Choose a reason for hiding this comment

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

It is in part, I was trying to unify the style and I do think really nested if/else blocks get confusing which is not the case here. But I have no knowledge about pipelining so if that's an issue I don't mind inverting the conditions again.

Copy link
Member

Choose a reason for hiding this comment

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

I think if you add an UNEXPECTED it should essentially be equivalent.

Girgias added 3 commits April 1, 2022 11:17
Mainly using more appropriate types, early returns,
and moving the happy path to the primary scope
@Girgias Girgias merged commit ef287bf into php:master Apr 23, 2022
@Girgias Girgias deleted the std-string-refactor branch April 23, 2022 11:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants