Closed Bug 368902 Opened 19 years ago Closed 19 years ago

Unnecessary looping over collapsed children in nsSprocketLayout

Categories

(Core :: Layout, defect)

defect
Not set
normal

Tracking

()

RESOLVED FIXED

People

(Reporter: andreas, Assigned: andreas)

References

()

Details

Attachments

(1 file)

Noticed while reading code for the deCOMtamination in bug 243370. This code is unchanged since revision 1.1 of the file (from back in 2000), so it certainly works, but it looks wrong! In pseudocode, we have the following functions: nsSprocketLayout::GetPrefSize(aBox, aState) { child = aBox->GetChild(); while (child) { // ignore collapsed children if (!child->isCollapsed(aState)) { /* ... add up child->GetPrefSize() */ } child = child->GetNextBox(); } } But, GetMinSize and GetMaxSize do this: nsSprocketLayout::GetMinSize(aBox, aState) { child = aBox->GetChild(); while (child) { // ignore collapsed children if (!aBox->isCollapsed(aState)) { /* ... add up child->GetMinSize() */ } child = child->GetNextBox(); } } Note that all functions iterate all children, but GetPrefSize uses |child->IsCollapsed()| as condition for doing anything with |child|, while GetMinSize and GetMaxSize check |aBox->IsCollapsed()| which certainly shouldn't change while within the loop! I don't know how to test this, but it looks like a thinko was made here and then got copied a few times. Before the deCOM this looked like PRBool isCollapsed; aBox->IsCollapsed(aState, &isCollapsed); while (!isCollapsed) which made it harder to see.
Attachment #253534 - Flags: review?(bzbarsky)
Status: NEW → ASSIGNED
Comment on attachment 253534 [details] [diff] [review] Change |aBox| to |child| where appropriate r+sr=bzbarsky The reason this happened to work is that the Get*Size impls also check IsCollapsed() and return 0x0 for min/pref and "infinite" size for max if the box is collapsed.
Attachment #253534 - Flags: superreview+
Attachment #253534 - Flags: review?(bzbarsky)
Attachment #253534 - Flags: review+
Assignee: nobody → anlan
Status: ASSIGNED → NEW
Whiteboard: [checkin needed]
layout/xul/base/src/nsSprocketLayout.cpp 1.54
Status: NEW → RESOLVED
Closed: 19 years ago
Resolution: --- → FIXED
Whiteboard: [checkin needed]
A testcase that would fail if comment 2 hadn't been in effect here would be nice.
Flags: in-testsuite?
Product: Core → Core Graveyard
Component: Layout: Misc Code → Layout
Product: Core Graveyard → Core
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: