Closed
Bug 158632
Opened 23 years ago
Closed 8 years ago
CNavDTD::CanContain calls unnecessary more times
Categories
(Core :: DOM: HTML Parser, defect)
Core
DOM: HTML Parser
Tracking
()
RESOLVED
FIXED
People
(Reporter: jerry.tan, Unassigned)
References
Details
(Keywords: perf)
Attachments
(2 files)
|
1.99 KB,
patch
|
Details | Diff | Splinter Review | |
|
812 bytes,
patch
|
Details | Diff | Splinter Review |
CNavDTD::CanContain(PRInt32 aParent,PRInt32 aChild) is to calculate if the
parent tag can contain the child tag according to html spec.
but some time, this function is called unnecessary more times.
see this testcase,
<body><table><td>Blueish bar</td></table></body>
I printf aparent,and a child at CNavDTD::CanContain(),
get such message
0-48
48-15
15-97
97-99
105-99
98-105
97-98
105-99
98-105
97-98
97-98
98-105
105-99
99-112
36-112
it seems that 97-98 is called three times, two times may be unnecessary.
Summary: CNavDTD::CanContain calls too much times → CNavDTD::CanContain calls unnecessary more times
Comment 2•23 years ago
|
||
*** Bug 158631 has been marked as a duplicate of this bug. ***
The reason for my testcase is that:
When parser meet "<td>", the parent tag is "<table>", CanPropagate() will
insert "<tbody>","<tr>" Token into stack accordingly, in the insert process,
CanContain() is called. But then when handle those inserted Tokens , CanContain
() will be called again.it is unnecessary, because the relationships is already
known.
One suggestion: when insert into stack token, set one flag,
if the flag is enabled, dont call CanContain() in the fuction
call of CNavDTD::HandleDefaultStartToken().
I printf aparent,and a child at CNavDTD::CanContain(),
when access <body><table><td>Test</table></body>,
return
0 -- 48
48 -- 15
15 -- 97
97 -- 99
105 -- 99
98 -- 105
97 -- 98
105 -- 99
98 -- 105
97 -- 98
97 -- 98
98 -- 105
105 -- 99
99 -- 112
36 -- 112
15 times calls to CanContain()
After add patch 0.1, return
0 -- 48
48 -- 15
15 -- 97
97 -- 99
105 -- 99
98 -- 105
97 -- 98
105 -- 99
98 -- 105
97 -- 98
105 -- 99
99 -- 112
36 -- 112
13 times function call.
Maybe we can reduce more.
Testcase: <table><td>
when parser meet <td>, it will create '<tbody>' and '<tr>' Token first, then
call
HandleToken() to handle the two Token.
During the process of HandleToken() for newly created Token---tbody, tr
the relationship of <table><tbody>, <tbody><tr> is already known,
so there is no need to calculate the relationship again.
So in patch 0.1, I skip CanContain() in handleToken() for newly created Token.
That will save 2 times funciton call for CanContain().
patch 0.2 is total different from patch 0.1
It is about another thing for this bug:
for testcase <table><td>, I found that:
During HandleDefaultStartToken() for '<td>',
it will call CanPropagate()
(http://lxr.mozilla.org/mozilla/source/htmlparser/src/CNavDTD.cpp#1304)
In this function, it will call ForwardPropagate(mScratch,theTop,aChildTag) to
set value for mScratch
Then HandleDefaultStartToken() will call CreateContextStackFor(),
in the function call of CreateContextStackFor(), it will call ForwardPropagate()
again with the same parameter
to set value for mScratch, even it is already been set before the call of
CreateContextStackFor().
So I made patch 0.2.
if mScratch.length>0, just skip.
after add patch 0.2, it will reduce function call to CanContain()
Testcase: <table><td>
trunk will call CanContain() 14 times.
add patch 0.2, reduce to 11 times.
Comment 10•23 years ago
|
||
What is the actual perf win here? Numbers?
What are the other callers of CreateContextStackFor()? Will this break any of them?
You want to be using mScrath.IsEmpty() here, I think, not checking .Length().
Updated•16 years ago
|
Assignee: harishd → nobody
QA Contact: moied → parser
Fixed by switching to the current parser.
Status: NEW → RESOLVED
Closed: 8 years ago
Resolution: --- → FIXED
You need to log in
before you can comment on or make changes to this bug.
Description
•