Opened 12 years ago
Closed 12 years ago
#30093 closed enhancement (fixed)
Codestyling and optimization
| Reported by: | ipm-frommen | Owned by: | SergeyBiryukov |
|---|---|---|---|
| Priority: | normal | Milestone: | 4.1 |
| Component: | Menus | Version: | |
| Severity: | normal | Keywords: | has-patch |
| Cc: | Focuses: | administration |
Description
Replace one-time do { ... } while (0) loop and subsequent break check with simple if.
Attachments (4)
Change History (13)
#1
@
12 years ago
- Focuses administration added; metabox removed
- Milestone Awaiting Review
- Resolution → wontfix
- Status new → closed
#2
@
12 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.
#5
follow-up:
↓ 8
@
12 years ago
- Resolution fixed
- Status closed → 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
@
12 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
@
12 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.