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

Add filter for non-repeatable fields #430

Merged
merged 2 commits into from Aug 13, 2015

Conversation

JPry
Copy link
Contributor

@JPry JPry commented Aug 13, 2015

This also streamlines how the field type is checked. Using isset() is more efficient than in_array().

This also streamlines how the field type is checked. isset() is more
efficient than in_array().
@jtsternberg
Copy link
Member

I'm not sure I understand the value of reversing this to use array keys?

@JPry
Copy link
Contributor Author

JPry commented Aug 13, 2015

@jtsternberg

I'm not sure I understand the value of reversing this to use array keys?

Here's a StackOverflow answer that should explain it.

@jtsternberg
Copy link
Member

I was familiar w/ the fact that isset is faster than in_array, but having a hard time believing the value gained from using array keys (for the number of items that would live in this array), is worth developer confusion w/ using this filter with array keys.
Convince me. ;)

@JPry
Copy link
Contributor Author

JPry commented Aug 13, 2015

@jtsternberg It's true that any single instance of this method being called won't produce any significant performance increase, and it may add some confusion. However, this method is called every single time an instance of CMB2_Field is created. There are 5 calls currently in CMB2, and a single call each in CMB2_Sanitize and CMB2_Types.

Taking into account multiple fields and multiple metaboxes, this very quickly increases by a significant factor. Thus, the performance improvement can add up and be worth the slight confusion developers may have.

@jtsternberg
Copy link
Member

Color me convinced. Thank you for thinking this through.

jtsternberg added a commit that referenced this pull request Aug 13, 2015
Add filter for non-repeatable fields
@jtsternberg jtsternberg merged commit c648540 into CMB2:trunk Aug 13, 2015
jtsternberg added a commit that referenced this pull request Aug 13, 2015
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.

None yet

3 participants