Closed
Bug 460512
Opened 17 years ago
Closed 17 years ago
Avoid AddRef/Release in scriptable helper methods for NodeList
Categories
(Core :: DOM: Core & HTML, defect)
Core
DOM: Core & HTML
Tracking
()
RESOLVED
FIXED
mozilla1.9.1b2
People
(Reporter: peterv, Assigned: peterv)
Details
Attachments
(1 file, 3 obsolete files)
|
120.17 KB,
patch
|
peterv
:
review+
peterv
:
superreview+
|
Details | Diff | Splinter Review |
This makes the dromaeo DOM tests about 2% faster (some specific tests get a bigger speedup).
Attachment #343594 -
Flags: superreview?(bzbarsky)
Attachment #343594 -
Flags: review?(bzbarsky)
Comment 1•17 years ago
|
||
Seems to me like it might be better to have a slightly more generic "this is a list" interface which returned nsISupports* and then perhaps we could have all the various other subclasses of nsArraySH implement it too? I'm not all that happy with this sort of copy/paste if we can avoid it...
If we do want to do this, then isn't calling GetProperty() on nsNodeList guaranteed to assert? Also, nsArraySH::doCreate should probably be private if it can.
| Assignee | ||
Comment 2•17 years ago
|
||
(In reply to comment #1)
> Seems to me like it might be better to have a slightly more generic "this is a
> list" interface which returned nsISupports* and then perhaps we could have all
> the various other subclasses of nsArraySH implement it too?
Sure, seems like a lot of work for little benefit though.
> If we do want to do this, then isn't calling GetProperty() on nsNodeList
> guaranteed to assert? Also, nsArraySH::doCreate should probably be private if
> it can.
How so? (assuming you mean nsNodeListSH::GetProperty)
Comment 3•17 years ago
|
||
> Sure, seems like a lot of work for little benefit though.
Well, the main benefit is avoiding copy/paste of fiddly code.
I'm also OK with said avoidance via macro-izing the relevant functions or something, I guess DO_SOME_STUFF(code) with |code| being two different things for the different parts.
> How so? (assuming you mean nsNodeListSH::GetProperty)
I did mean that. I somehow missed that it implements GetProperty, so nevermind that part. :(
| Assignee | ||
Comment 4•17 years ago
|
||
Patch is quite a bit bigger :-/. Did run mochitests, no regressions.
Attachment #343594 -
Attachment is obsolete: true
Attachment #343919 -
Flags: superreview?(bzbarsky)
Attachment #343919 -
Flags: review?(bzbarsky)
Attachment #343594 -
Flags: superreview?(bzbarsky)
Attachment #343594 -
Flags: review?(bzbarsky)
| Assignee | ||
Comment 5•17 years ago
|
||
Note that I could add assertions in all the FromSupports implementations in case anyone derives a class from one of those classes and uses a different class for the canonical nsISupports pointer.
Comment 6•17 years ago
|
||
Comment on attachment 343919 [details] [diff] [review]
v2
>+++ b/content/html/content/public/nsIHTMLCollection.h
>+class nsINode;
Not needed, right?
>+++ b/content/html/content/src/nsHTMLFormElement.cpp
> nsFormControlList::Item(PRUint32 aIndex, nsIDOMNode** aReturn)
> {
>+ nsresult rv;
>+ nsISupports* item = GetNodeAt(aIndex, &rv);
>
>+ return item ? CallQueryInterface(item, aReturn) : rv;
So if aIndex is out of bounds we'll return NS_OK (the only thing GetNodeAt() ever sticks in rv) but not set *aReturn? That seems suboptimal. Can we set *aReturn to null here?
>+++ b/content/html/content/src/nsHTMLSelectElement.cpp
> nsHTMLOptionCollection::Item(PRUint32 aIndex, nsIDOMNode** aReturn)
Same issue here.
>+// Returns the item at index aIndex, if available. aCount will be 0 if an item
>+// is found or the length of rows otherwise.
>+static nsINode*
> GetItemOrCountInRowGroup(nsIDOMHTMLCollection* rows,
I don't think that comment is correct. What the function really does is:
Returns the item at index aIndex if available. If null is returned,
then aCount will be set to the number of rows in this row collection.
Otherwise, the value of aCount is undefined.
>+TableRowsCollection::Item(PRUint32 aIndex, nsIDOMNode** aReturn)
This needs to set *aReturn if GetNodeAt returns null.
>--- a/dom/src/offline/nsDOMOfflineLoadStatusList.cpp
Please check with dcamp about this stuff.
>+++ b/layout/style/nsCSSRules.cpp
>+CSSGroupRuleRuleListImpl::Item(PRUint32 aIndex, nsIDOMCSSRule** aReturn)
Need to set *aReturn if GetItemAt returns null.
> nsCSSFontFaceStyleDecl::GetParentRule(nsIDOMCSSRule** aParentRule)
>+ return static_cast<nsICSSRule*>(ContainingRule())->GetDOMRule(aParentRule);
Why is that cast needed?
>+++ b/layout/style/nsCSSStyleSheet.cpp
>+CSSRuleListImpl::Item(PRUint32 aIndex, nsIDOMCSSRule** aReturn)
Needs to always set *aReturn, no?
Adding the assertions would be nice if you can do it.
r+sr=bzbarsky with the above nits fixed and if dcamp is ok with that removal.
Attachment #343919 -
Flags: superreview?(bzbarsky)
Attachment #343919 -
Flags: superreview+
Attachment #343919 -
Flags: review?(dcamp)
Attachment #343919 -
Flags: review?(bzbarsky)
Attachment #343919 -
Flags: review+
Comment 7•17 years ago
|
||
Comment on attachment 343919 [details] [diff] [review]
v2
Yeah, that should have been removed.
Attachment #343919 -
Flags: review?(dcamp) → review+
| Assignee | ||
Comment 8•17 years ago
|
||
(In reply to comment #6)
> > nsCSSFontFaceStyleDecl::GetParentRule(nsIDOMCSSRule** aParentRule)
> >+ return static_cast<nsICSSRule*>(ContainingRule())->GetDOMRule(aParentRule);
>
> Why is that cast needed?
Otherwise I get:
nsCSSRules.cpp: In member function ‘virtual nsresult nsCSSFontFaceStyleDecl::GetParentRule(nsIDOMCSSRule**)’:
nsCSSRules.cpp:1753: error: no matching function for call to ‘nsCSSFontFaceRule::GetDOMRule(nsIDOMCSSRule**&)’
nsCSSRules.h:262: note: candidates are: virtual nsIDOMCSSRule* nsCSSFontFaceRule::GetDOMRule(nsresult*)
Seems I can't call the inline nsICSSRule::GetDOMRule without that cast.
Comment 9•17 years ago
|
||
Oh, because the child class declarations hide it. I bet you get compile warnings about that too.... <sigh>.
I guess if we want to leave the names as-is, add a comment there explaining why the cast is necessary.
| Assignee | ||
Comment 10•17 years ago
|
||
Attachment #343919 -
Attachment is obsolete: true
Attachment #344152 -
Flags: superreview+
Attachment #344152 -
Flags: review+
| Assignee | ||
Comment 11•17 years ago
|
||
I guess I could name the new method GetDOMRuleWeak.
| Assignee | ||
Comment 12•17 years ago
|
||
Renamed GetDOMRule to GetDOMRuleWeak to avoid name conflict. Boris, I'm assuming you're ok with that, speak up if you're not :-).
Attachment #344152 -
Attachment is obsolete: true
Attachment #344284 -
Flags: superreview+
Attachment #344284 -
Flags: review+
Comment 13•17 years ago
|
||
Sounds fine to me.
| Assignee | ||
Updated•17 years ago
|
Status: ASSIGNED → RESOLVED
Closed: 17 years ago
Resolution: --- → FIXED
Updated•6 years ago
|
Component: DOM → DOM: Core & HTML
You need to log in
before you can comment on or make changes to this bug.
Description
•