Bug 101820

Summary: axObjectCache code is more complicated than necessary
Product: WebKit Reporter: Adam Barth <abarth>
Component: New BugsAssignee: Adam Barth <abarth>
Status: RESOLVED FIXED    
Severity: Normal CC: darin, eric, webkit.review.bot
Priority: P2    
Version: 528+ (Nightly build)   
Hardware: Unspecified   
OS: Unspecified   
Attachments:
Description Flags
Patch
none
Patch for landing none

Adam Barth
Reported 2012-11-09 17:38:14 PST
axObjectCache code is more complicated than necessary
Attachments
Patch (5.16 KB, patch)
2012-11-09 17:39 PST, Adam Barth
no flags
Patch for landing (4.91 KB, patch)
2012-11-11 15:31 PST, Adam Barth
no flags
Adam Barth
Comment 1 2012-11-09 17:39:36 PST
Darin Adler
Comment 2 2012-11-09 18:13:02 PST
Comment on attachment 173416 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=173416&action=review > Source/WebCore/dom/Document.cpp:2204 > + // Clear the cache member variable before calling delete because attempts > + // are made to access it during destruction. > + OwnPtr<AXObjectCache> axObjectCache = topDocument()->m_axObjectCache.release(); No need to put the result of release into a local variable. This can just be: topDocument()->m_axObjectCache.release(); > Source/WebCore/dom/Document.cpp:2223 > + Document* document = topDocument(); > + ASSERT(document == this || !m_axObjectCache); > + if (document->m_axObjectCache) > + return document->m_axObjectCache.get(); > + document->m_axObjectCache = adoptPtr(new AXObjectCache(this)); > + return document->m_axObjectCache.get(); I prefer to write such things as: if (!document->m_axObjectCache) document->m_axObjectCache = adoptPtr(new AXObjectCache(this)); return document->m_axObjectCache.get(); But also, I suggest writing this instead: ASSERT(this = topDocument() || !m_axObjectCache); if (!m_axObjectCache) m_axObjectCache = adoptPtr(new AXObjectCache(this)); return m_axObjectCache.get();
Darin Adler
Comment 3 2012-11-09 18:15:16 PST
Comment on attachment 173416 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=173416&action=review >> Source/WebCore/dom/Document.cpp:2223 >> + return document->m_axObjectCache.get(); > > I prefer to write such things as: > > if (!document->m_axObjectCache) > document->m_axObjectCache = adoptPtr(new AXObjectCache(this)); > return document->m_axObjectCache.get(); > > But also, I suggest writing this instead: > > ASSERT(this = topDocument() || !m_axObjectCache); > if (!m_axObjectCache) > m_axObjectCache = adoptPtr(new AXObjectCache(this)); > return m_axObjectCache.get(); Oops! ASSERT(this == topDocument() || !m_axObjectCache);
Adam Barth
Comment 4 2012-11-11 15:29:12 PST
(In reply to comment #2) > (From update of attachment 173416 [details]) > View in context: https://bugs.webkit.org/attachment.cgi?id=173416&action=review > > > Source/WebCore/dom/Document.cpp:2204 > > + // Clear the cache member variable before calling delete because attempts > > + // are made to access it during destruction. > > + OwnPtr<AXObjectCache> axObjectCache = topDocument()->m_axObjectCache.release(); > > No need to put the result of release into a local variable. This can just be: > > topDocument()->m_axObjectCache.release(); Done. > > Source/WebCore/dom/Document.cpp:2223 > > + Document* document = topDocument(); > > + ASSERT(document == this || !m_axObjectCache); > > + if (document->m_axObjectCache) > > + return document->m_axObjectCache.get(); > > + document->m_axObjectCache = adoptPtr(new AXObjectCache(this)); > > + return document->m_axObjectCache.get(); > > I prefer to write such things as: > > if (!document->m_axObjectCache) > document->m_axObjectCache = adoptPtr(new AXObjectCache(this)); > return document->m_axObjectCache.get(); Done. > But also, I suggest writing this instead: > > ASSERT(this = topDocument() || !m_axObjectCache); > if (!m_axObjectCache) > m_axObjectCache = adoptPtr(new AXObjectCache(this)); > return m_axObjectCache.get(); I'm nit sure I understand. If Document::axObjectCache() is called on a non-top document, won't this code create a new object cache for that document? It's a bit strange that we have a m_axObjectCache pointer for every Document but we only use it for top documents. It seems like it might be better to store that pointer on Page. I wandered into this code because Document::axObjectCache is showing up on profiles for Dromeo's dom-modify benchmark (because it is called in Element::attributeChanged). I thing was I would first modernize the code to use OwnPtr and then see about getting it off the profile.
Adam Barth
Comment 5 2012-11-11 15:29:42 PST
s/nit/not/
Adam Barth
Comment 6 2012-11-11 15:31:43 PST
Created attachment 173520 [details] Patch for landing
WebKit Review Bot
Comment 7 2012-11-11 16:30:19 PST
Comment on attachment 173520 [details] Patch for landing Clearing flags on attachment: 173520 Committed r134178: <http://trac.webkit.org/changeset/134178>
WebKit Review Bot
Comment 8 2012-11-11 16:30:23 PST
All reviewed patches have been landed. Closing bug.
Darin Adler
Comment 9 2012-11-12 10:40:31 PST
(In reply to comment #4) > I'm nit sure I understand. If Document::axObjectCache() is called on a non-top document, won't this code create a new object cache for that document? Yes, I misunderstood the code. > It's a bit strange that we have a m_axObjectCache pointer for every Document but we only use it for top documents. It seems like it might be better to store that pointer on Page. Possibly. Page comes with its own problems because it can be 0 for during the end of a frame’s lifetime. But we did create Page originally to try to move top document and top frame data structures out of the Frame/Document family of classes. > I wandered into this code because Document::axObjectCache is showing up on profiles for Dromeo's dom-modify benchmark (because it is called in Element::attributeChanged). I thing was I would first modernize the code to use OwnPtr and then see about getting it off the profile. Sure does sound like a great plan!
Darin Adler
Comment 10 2012-11-12 10:42:51 PST
(In reply to comment #9) > (In reply to comment #4) > > I'm nit sure I understand. If Document::axObjectCache() is called on a non-top document, won't this code create a new object cache for that document? > > Yes, I misunderstood the code. If I had understood better what was going on, I would have suggested naming the local variable topDocument: Document* topDocument = this->topDocument();
Adam Barth
Comment 11 2012-11-12 11:18:46 PST
> If I had understood better what was going on, I would have suggested naming the local variable topDocument: Good idea. Will fix shortly.
Adam Barth
Comment 12 2012-11-12 12:25:23 PST
Name change is in bug 101966.
Note You need to log in before you can comment on or make changes to this bug.