Skip to content

Add filter for non-repeatable fields - #430

Merged
jtsternberg merged 2 commits into
CMB2:trunkfrom
JPry:repeatable_field_filter
Aug 13, 2015
Merged

Add filter for non-repeatable fields#430
jtsternberg merged 2 commits into
CMB2:trunkfrom
JPry:repeatable_field_filter

Conversation

@JPry

@JPryJPry commented Aug 13, 2015

Copy link
Copy Markdown
Contributor

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
Copy Markdown
Member

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

@JPry

JPry commented Aug 13, 2015

Copy link
Copy Markdown
ContributorAuthor

@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
Copy Markdown
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

JPry commented Aug 13, 2015

Copy link
Copy Markdown
ContributorAuthor

@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
Copy Markdown
Member

Color me convinced. Thank you for thinking this through.

jtsternberg added a commit that referenced this pull request Aug 13, 2015
@jtsternberg
jtsternberg merged commit c648540 into CMB2:trunkAug 13, 2015
jtsternberg added a commit that referenced this pull request Aug 13, 2015
Sign up for freeto 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

@JPry@jtsternberg@gregrickaby