Make WordPress Core

Opened 11 years ago

Closed 11 years ago

#30093 closed enhancement (fixed)

Codestyling and optimization

Reported by: ipm-frommen's profile ipm-frommen Owned by: sergeybiryukov's profile SergeyBiryukov
Milestone: 4.1 Priority: normal
Severity: normal Version:
Component: Menus Keywords: has-patch
Focuses: administration Cc:

Description

Replace one-time do { ... } while (0) loop and subsequent break check with simple if.

Attachments (4)

30093.diff (961 bytes) - added by ipm-frommen 11 years ago.
30093-2.diff (2.1 KB) - added by ipm-frommen 11 years ago.
30093-3.diff (2.1 KB) - added by ipm-frommen 11 years ago.
THIS is the correct second dif, as in 30093-2 there was a mistake (& instead of &&)
30093-4.diff (1.9 KB) - added by ipm-frommen 11 years ago.

Download all attachments as: .zip

Change History (13)

@ipm-frommen
11 years ago

#1 @DrewAPicture
11 years ago

  • Focuses administration added; metabox removed
  • Milestone Awaiting Review deleted
  • Resolution set to wontfix
  • Status changed from new to closed

Hi ipm-frommen,

Thank you for the patch. Unfortunately, we generally avoid refactoring for the sake of refactoring. For more information, check out this post on the make/core blog.

#2 @SergeyBiryukov
11 years ago

These checks are actually redundant, the one inside the foreach() loop (line 1119) is enough.

We have a precedent for removing extra code like this in [23722].

Let's keep isset( $wp_meta_boxes[ $page ][ $context ] ) though, to avoid reformatting the whole block.

#3 @SergeyBiryukov
11 years ago

  • Owner set to SergeyBiryukov
  • Resolution changed from wontfix to fixed

In 30022:

Remove one-time loop and redundant isset() checks.

props ipm-frommen.
fixes #30093.

#4 @SergeyBiryukov
11 years ago

  • Component changed from General to Menus
  • Milestone set to 4.1

Introduced in [23707].

#5 follow-up: @nacin
11 years ago

  • Resolution fixed deleted
  • Status changed from closed to reopened

There's the same thing in another function here.

I highly doubt that this do while(0) loop was done without good reason, originally. Curious when it was originally introduced in do_meta_boxes() what that reason was. I'd imagine multiple breaks.

@ipm-frommen
11 years ago

#6 @ipm-frommen
11 years ago

Hi Andrew,

I'm not sure I interpreted your comment correctly.
If you weren't asking for another diff (regarding the second do-while(0) loop, which I missed), I'm sorry - but here it is. :) See new attached file 30093-3.diff.

I also removed the (static) variable $already_sorted as there was no need for it (anymore?).

EDIT
Like you, I also assume a reason for the do-while(0) constructs - but there is none to be seen.
I also searched through the revisions, and the oldest I could find, 17007, already contains the loop with this single break check.

Last edited 11 years ago by ipm-frommen (previous) (diff)

@ipm-frommen
11 years ago

THIS is the correct second dif, as in 30093-2 there was a mistake (& instead of &&)

#7 @ipm-frommen
11 years ago

When I reviewed (and rethought) the sorting block within do_meta_boxes I realized that using the $already_sorted variable, in fact, is a good idea, because the function is being called several times - and sorting the metaboxes needs to be done just once.

So here is yet another diff, 30093-4.diff, containing just what this ticket is about: refactoring/improving the do-while(0) loop.

I'd be happy if someone could delete the two attachments 30093-2.diff and 30093-3.diff - just because they're faulty and irrelevant. Sorry for that. :(

@ipm-frommen
11 years ago

#8 in reply to: ↑ 5 @SergeyBiryukov
11 years ago

Replying to nacin:

I highly doubt that this do while(0) loop was done without good reason, originally. Curious when it was originally introduced in do_meta_boxes() what that reason was. I'd imagine multiple breaks.

Introduced in [8682], no multiple breaks there.

#9 @SergeyBiryukov
11 years ago

  • Resolution set to fixed
  • Status changed from reopened to closed

In 30040:

Remove one-time loop and redundant isset() checks in do_meta_boxes().

See [30022] for do_accordion_sections().

props ipm-frommen.
fixes #30093.

Note: See TracTickets for help on using tickets.