Opened 11 years ago
Closed 11 years ago
#30093 closed enhancement (fixed)
Codestyling and optimization
| Reported by: |
|
Owned by: |
|
|---|---|---|---|
| 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)
Change History (13)
#1
@
11 years ago
- Focuses administration added; metabox removed
- Milestone Awaiting Review deleted
- Resolution set to wontfix
- Status changed from new to closed
#2
@
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.
#4
@
11 years ago
- Component changed from General to Menus
- Milestone set to 4.1
Introduced in [23707].
#5
follow-up:
↓ 8
@
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.
#6
@
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.
#7
@
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. :(
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.