Closed
Bug 333942
Opened 18 years ago
Closed 18 years ago
Implement GetNodeParent
Categories
(Core :: DOM: Core & HTML, defect)
Core
DOM: Core & HTML
Tracking
()
RESOLVED
FIXED
People
(Reporter: sicking, Assigned: sicking)
References
(Depends on 1 open bug)
Details
Attachments
(1 file)
18.98 KB,
patch
|
bzbarsky
:
review+
bzbarsky
:
superreview+
|
Details | Diff | Splinter Review |
We should move nsIContent::GetParent to nsINode since that might save some casting when nsINode becomes more widely used. Additionally, we should add a function that returns the parent as an nsINode which would return a non-null value even when the parent is a document or an attribute.
Assignee | ||
Comment 1•18 years ago
|
||
The biggest problem with this patch is that it adds an |if| check for each GetParent. However I can't think of a way around that and still keeping GetNodeParent as fast as GetParent. Additionally, it doesn't make GetNodeParent return the attribute for children of attributes (since there is no way to pass that in to BindToTree). However that doesn't feel very important so I'll leave that for a separate bug.
Attachment #218387 -
Flags: superreview?(bzbarsky)
Attachment #218387 -
Flags: review?(bzbarsky)
Comment 2•18 years ago
|
||
Comment on attachment 218387 [details] [diff] [review] Patch to fix >Index: content/base/public/nsINode.h >+ nsIContent* GetParent() const >+ { >+ return mParentPtrBits & PARENT_BIT_PARENT_IS_CONTENT ? >+ NS_REINTERPRET_CAST(nsIContent*, >+ mParentPtrBits & ~kParentBitMask) : >+ nsnull; Maybe more like: if (NS_LIKELY(mParentPtrBits & PARENT_BIT_PARENT_IS_CONTENT)) { return ...; } return nsnull; or do we not really think that this will be likely? I guess I'm ok either way... >+ * Get the parent nsIContent for this node. >+ * @return the parent, or null if no parent or the parent is not an nsIContent For GetNodeParent(), this comment looks wrong. >Index: content/base/src/nsGenericDOMDataNode.cpp >+ NS_PRECONDITION(!GetCurrentDoc() && >+ !IsInDoc(), "Already have a document. Unbind first!"); I'd put the "!IsInDoc()," part before the line break. > nsGenericDOMDataNode::UnbindFromTree(PRBool aDeep, PRBool aNullParent) > mParentPtrBits &= ~PARENT_BIT_INDOCUMENT; > if (aNullParent) { >- mParentPtrBits &= nsIContent::kParentBitMask; >+ mParentPtrBits = 0; > } Maybe we should do the &= thing only in the else (when !aNullParent)? Same in nsGenericElement::UnbindFromTree and nsXULElement::UnbindFromTree? This last needs to have this code tweaked, btw... r+sr=bzbarsky with those nits.
Attachment #218387 -
Flags: superreview?(bzbarsky)
Attachment #218387 -
Flags: superreview+
Attachment #218387 -
Flags: review?(bzbarsky)
Attachment #218387 -
Flags: review+
Assignee | ||
Comment 3•18 years ago
|
||
> >+ nsIContent* GetParent() const > >+ { > >+ return mParentPtrBits & PARENT_BIT_PARENT_IS_CONTENT ? > >+ NS_REINTERPRET_CAST(nsIContent*, > >+ mParentPtrBits & ~kParentBitMask) : > >+ nsnull; > > Maybe more like: > > if (NS_LIKELY(mParentPtrBits & PARENT_BIT_PARENT_IS_CONTENT)) { > return ...; > } > > return nsnull; > > or do we not really think that this will be likely? I guess I'm ok either > way... I do think it is likely so I added the NS_LIKELY, however I think some compilers aren't too good at inline functions that contains multiple returns, so I kept the :? > > nsGenericDOMDataNode::UnbindFromTree(PRBool aDeep, PRBool aNullParent) > > mParentPtrBits &= ~PARENT_BIT_INDOCUMENT; > > if (aNullParent) { > >- mParentPtrBits &= nsIContent::kParentBitMask; > >+ mParentPtrBits = 0; > > } > > Maybe we should do the &= thing only in the else (when !aNullParent)? Switched to a :? syntax
Assignee | ||
Comment 4•18 years ago
|
||
So this added 4-4.5k to buildsize. Ideally it wouldn't, but I don't think there's a way around it. And it should save save us in other places where we can simplify code.
Assignee | ||
Updated•18 years ago
|
Status: NEW → RESOLVED
Closed: 18 years ago
Resolution: --- → FIXED
Updated•5 years ago
|
Component: DOM → DOM: Core & HTML
You need to log in
before you can comment on or make changes to this bug.
Description
•