gPictureOwnerMap is unnecessary
authorrniwa@webkit.org <rniwa@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 4 Mar 2019 22:00:28 +0000 (22:00 +0000)
committerrniwa@webkit.org <rniwa@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 4 Mar 2019 22:00:28 +0000 (22:00 +0000)
https://bugs.webkit.org/show_bug.cgi?id=195228

Reviewed by Zalan Bujtas.

Just store in HTMLImageElement. An extra pointer isn't going to affect the memory use here.
If anything, we should worry about m_editableImage and m_pendingClonedAttachmentID instead.

* html/HTMLImageElement.cpp:
(WebCore::HTMLImageElement::pictureElement const):
(WebCore::HTMLImageElement::setPictureElement):
* html/HTMLImageElement.h:

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@242391 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebCore/ChangeLog
Source/WebCore/html/HTMLImageElement.cpp
Source/WebCore/html/HTMLImageElement.h

index 78b0b0e..df501d1 100644 (file)
@@ -1,3 +1,18 @@
+2019-03-01  Ryosuke Niwa  <rniwa@webkit.org>
+
+        gPictureOwnerMap is unnecessary
+        https://bugs.webkit.org/show_bug.cgi?id=195228
+
+        Reviewed by Zalan Bujtas.
+
+        Just store in HTMLImageElement. An extra pointer isn't going to affect the memory use here.
+        If anything, we should worry about m_editableImage and m_pendingClonedAttachmentID instead.
+
+        * html/HTMLImageElement.cpp:
+        (WebCore::HTMLImageElement::pictureElement const):
+        (WebCore::HTMLImageElement::setPictureElement):
+        * html/HTMLImageElement.h:
+
 2019-03-04  Daniel Bates  <dabates@apple.com>
 
         [iOS] Caret x-position in empty text area does not match text field
index a19c20d..5cc8b39 100644 (file)
@@ -67,9 +67,6 @@ WTF_MAKE_ISO_ALLOCATED_IMPL(HTMLImageElement);
 
 using namespace HTMLNames;
 
-typedef HashMap<const HTMLImageElement*, WeakPtr<HTMLPictureElement>> PictureOwnerMap;
-static PictureOwnerMap* gPictureOwnerMap = nullptr;
-
 HTMLImageElement::HTMLImageElement(const QualifiedName& tagName, Document& document, HTMLFormElement* form)
     : HTMLElement(tagName, document)
     , m_imageLoader(*this)
@@ -454,25 +451,12 @@ void HTMLImageElement::updateEditableImage()
 
 HTMLPictureElement* HTMLImageElement::pictureElement() const
 {
-    if (!gPictureOwnerMap || !gPictureOwnerMap->contains(this))
-        return nullptr;
-    auto result = gPictureOwnerMap->get(this);
-    if (!result)
-        gPictureOwnerMap->remove(this);
-    return result.get();
+    return m_pictureElement.get();
 }
     
 void HTMLImageElement::setPictureElement(HTMLPictureElement* pictureElement)
 {
-    if (!pictureElement) {
-        if (gPictureOwnerMap)
-            gPictureOwnerMap->remove(this);
-        return;
-    }
-    
-    if (!gPictureOwnerMap)
-        gPictureOwnerMap = new PictureOwnerMap();
-    gPictureOwnerMap->add(this, makeWeakPtr(*pictureElement));
+    m_pictureElement = makeWeakPtr(pictureElement);
 }
     
 unsigned HTMLImageElement::width(bool ignorePendingStylesheets)
index 8995cbf..d20fa72 100644 (file)
@@ -185,6 +185,8 @@ private:
     bool m_hadNameBeforeAttributeChanged { false }; // FIXME: We only need this because parseAttribute() can't see the old value.
 
     RefPtr<EditableImageReference> m_editableImage;
+    WeakPtr<HTMLPictureElement> m_pictureElement;
+
 #if ENABLE(ATTACHMENT_ELEMENT)
     String m_pendingClonedAttachmentID;
 #endif