Title: [204006] trunk/Source/WebCore
Revision
204006
Author
akl...@apple.com
Date
2016-08-01 18:44:43 -0700 (Mon, 01 Aug 2016)

Log Message

Shrink MediaQuerySets to fit after parsing.
<https://webkit.org/b/160419>

Reviewed by Antti Koivisto.

Add shrinkToFit() helpers to MediaQuerySet and MediaQuery
and call it after parsing to remove extra capacity from their
internal vectors.

This reduces memory usage by 1.24MB on theverge.com.

* css/CSSParser.cpp:
(WebCore::CSSParser::createMediaRule):
* css/MediaList.cpp:
(WebCore::MediaQuerySet::parse):
(WebCore::MediaQuerySet::shrinkToFit):
* css/MediaList.h:
* css/MediaQuery.h:
(WebCore::MediaQuery::shrinkToFit):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (204005 => 204006)


--- trunk/Source/WebCore/ChangeLog	2016-08-02 01:39:26 UTC (rev 204005)
+++ trunk/Source/WebCore/ChangeLog	2016-08-02 01:44:43 UTC (rev 204006)
@@ -1,3 +1,25 @@
+2016-08-01  Andreas Kling  <akl...@apple.com>
+
+        Shrink MediaQuerySets to fit after parsing.
+        <https://webkit.org/b/160419>
+
+        Reviewed by Antti Koivisto.
+
+        Add shrinkToFit() helpers to MediaQuerySet and MediaQuery
+        and call it after parsing to remove extra capacity from their
+        internal vectors.
+
+        This reduces memory usage by 1.24MB on theverge.com.
+
+        * css/CSSParser.cpp:
+        (WebCore::CSSParser::createMediaRule):
+        * css/MediaList.cpp:
+        (WebCore::MediaQuerySet::parse):
+        (WebCore::MediaQuerySet::shrinkToFit):
+        * css/MediaList.h:
+        * css/MediaQuery.h:
+        (WebCore::MediaQuery::shrinkToFit):
+
 2016-08-01  Tim Horton  <timothy_hor...@apple.com>
 
         <attachment> action label doesn't wrap, but needs to for some localizations

Modified: trunk/Source/WebCore/css/CSSParser.cpp (204005 => 204006)


--- trunk/Source/WebCore/css/CSSParser.cpp	2016-08-02 01:39:26 UTC (rev 204005)
+++ trunk/Source/WebCore/css/CSSParser.cpp	2016-08-02 01:44:43 UTC (rev 204006)
@@ -12905,8 +12905,10 @@
         // To comply with w3c test suite expectation, create an empty media query
         // even when it is syntactically incorrect.
         rule = StyleRuleMedia::create(MediaQuerySet::create(), emptyRules);
-    } else
+    } else {
+        media->shrinkToFit();
         rule = StyleRuleMedia::create(media.releaseNonNull(), rules ? *rules : emptyRules);
+    }
     processAndAddNewRuleToSourceTreeIfNeeded();
     return rule.releaseNonNull();
 }

Modified: trunk/Source/WebCore/css/MediaList.cpp (204005 => 204006)


--- trunk/Source/WebCore/css/MediaList.cpp	2016-08-02 01:39:26 UTC (rev 204005)
+++ trunk/Source/WebCore/css/MediaList.cpp	2016-08-02 01:44:43 UTC (rev 204006)
@@ -158,6 +158,7 @@
             return false;
     }
     m_queries = WTFMove(result);
+    shrinkToFit();
     return true;
 }
 
@@ -198,6 +199,13 @@
     return text.toString();
 }
 
+void MediaQuerySet::shrinkToFit()
+{
+    m_queries.shrinkToFit();
+    for (auto& query : m_queries)
+        query.shrinkToFit();
+}
+
 MediaList::MediaList(MediaQuerySet* mediaQueries, CSSStyleSheet* parentSheet)
     : m_mediaQueries(mediaQueries)
     , m_parentStyleSheet(parentSheet)

Modified: trunk/Source/WebCore/css/MediaList.h (204005 => 204006)


--- trunk/Source/WebCore/css/MediaList.h	2016-08-02 01:39:26 UTC (rev 204005)
+++ trunk/Source/WebCore/css/MediaList.h	2016-08-02 01:44:43 UTC (rev 204006)
@@ -66,6 +66,8 @@
 
     Ref<MediaQuerySet> copy() const { return adoptRef(*new MediaQuerySet(*this)); }
 
+    void shrinkToFit();
+
 private:
     MediaQuerySet();
     MediaQuerySet(const String& mediaQuery, bool fallbackToDescription);

Modified: trunk/Source/WebCore/css/MediaQuery.h (204005 => 204006)


--- trunk/Source/WebCore/css/MediaQuery.h	2016-08-02 01:39:26 UTC (rev 204005)
+++ trunk/Source/WebCore/css/MediaQuery.h	2016-08-02 01:44:43 UTC (rev 204006)
@@ -49,6 +49,8 @@
 
     bool operator==(const MediaQuery& other) const;
 
+    void shrinkToFit() { m_expressions.shrinkToFit(); }
+
 private:
     String serialize() const;
 
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to