Closed
Bug 368902
Opened 19 years ago
Closed 19 years ago
Unnecessary looping over collapsed children in nsSprocketLayout
Categories
(Core :: Layout, defect)
Core
Layout
Tracking
()
RESOLVED
FIXED
People
(Reporter: andreas, Assigned: andreas)
References
()
Details
Attachments
(1 file)
|
2.23 KB,
patch
|
bzbarsky
:
review+
bzbarsky
:
superreview+
|
Details | Diff | Splinter Review |
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.
| Assignee | ||
Comment 1•19 years ago
|
||
| Assignee | ||
Updated•19 years ago
|
Attachment #253534 -
Flags: review?(bzbarsky)
| Assignee | ||
Updated•19 years ago
|
Status: NEW → ASSIGNED
Comment 2•19 years ago
|
||
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+
Updated•19 years ago
|
Assignee: nobody → anlan
Status: ASSIGNED → NEW
Whiteboard: [checkin needed]
Comment 3•19 years ago
|
||
layout/xul/base/src/nsSprocketLayout.cpp 1.54
Status: NEW → RESOLVED
Closed: 19 years ago
Resolution: --- → FIXED
Whiteboard: [checkin needed]
Comment 4•19 years ago
|
||
A testcase that would fail if comment 2 hadn't been in effect here would be nice.
Flags: in-testsuite?
Updated•7 years ago
|
Product: Core → Core Graveyard
Updated•7 years ago
|
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.
Description
•