Skip to content
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

HashTable Implemented #20832

Merged
merged 1 commit into from
Aug 7, 2018

Conversation

khanrn
Copy link
Contributor

@khanrn khanrn commented Jul 18, 2018

All Submissions:

Changes proposed in this Pull Request:

Here I've used HashTable to achieve the same output as achieved bystr(i)pos. Here HashTable is more efficient.

Closes this below comment-

// TODO: Fix conditional to only include shipping/billing address fields in a smarter way without str(i)pos. 

Reference:

https://stackoverflow.com/a/4106654/2740232

Other information:

  • Have you added an explanation of what your changes do and why you'd like us to include them?
  • Have you written new tests for your changes, as applicable?
  • Have you successfully ran tests with your changes locally?

Copy link
Member

@kloon kloon left a comment

Choose a reason for hiding this comment

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

Good first shot, although I find it a bit messy and dificult to read, you can do the first check with preg_match on /shipping_|billing_/ and then keep the in_array check on the nested if.

@kloon kloon added needs: author feedback The issue/PR needs a response from any of the parties involved in the issue. and removed status: needs review labels Aug 7, 2018
@kloon kloon added this to the 3.5.0 milestone Aug 7, 2018
@khanrn
Copy link
Contributor Author

khanrn commented Aug 7, 2018

But @kloon we are doing this inside of a foreach loop, means frequently or on multiple fields. So, I think for this issue preg_match and in_array will be more time and resource consuming than checking an array element after explode.
Lastly, with all due respect I disagree that this is less readable. 🙂 The previous version seemed to me much complected to read and understand.

@kloon
Copy link
Member

kloon commented Aug 7, 2018

@rnaby I did not imply it is less readable than what we currently have, was referring to all the nested function calls within each other. With regex you can achieve that in one if statement and not two like this

if ( preg_match( '/shipping_|billing_/', $key ) && ! in_array( $key, array( 'shipping_method', 'shipping_total', 'shipping_tax' ), true ) ) {

Speed wise, yes the regex will be slower, but we are talking about a 0.03ms difference across the whole loop which is pretty much negligible, yes I wrote a script to test this actually.

Anyway, thanks for the contribution, will approve and merge as is.

@woocommercebot woocommercebot added status: approved and removed needs: author feedback The issue/PR needs a response from any of the parties involved in the issue. labels Aug 7, 2018
@kloon kloon merged commit 70e9b74 into woocommerce:master Aug 7, 2018
@khanrn khanrn deleted the 180718-010448-class-wc-checkout branch August 13, 2018 05:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants