2010-08-30 Maciej Stachowiak <mjs@apple.com>
authormjs@apple.com <mjs@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 8 Sep 2010 11:08:08 +0000 (11:08 +0000)
committermjs@apple.com <mjs@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 8 Sep 2010 11:08:08 +0000 (11:08 +0000)
        Reviewed by Darin Adler.

        Handle MediaQueryExp memory management exclusively with smart pointers
        https://bugs.webkit.org/show_bug.cgi?id=44874

        Implemented a non-copying sort function to make it possible to sort a Vector
        of OwnPtrs (which cannot be copied). This is required for the above.

        * wtf/NonCopyingSort.h: Added.
        (WTF::nonCopyingSort): It's secretly heapsort.
        (WTF::heapSort): heapsort implementation.
        (WTF::siftDown): Helper function for heapsort.
        (WTF::heapify): ditto

        Adjust build systems.

        * GNUmakefile.am:
        * JavaScriptCore.gypi:
        * JavaScriptCore.vcproj/WTF/WTF.vcproj:
        * JavaScriptCore.xcodeproj/project.pbxproj:
2010-08-30  Maciej Stachowiak  <mjs@apple.com>

        Reviewed by Darin Adler.

        Handle MediaQueryExp memory management exclusively with smart pointers
        https://bugs.webkit.org/show_bug.cgi?id=44874

        Gace MediaQueryExp a create function, made the constructor private, and followed
        the implications. The one tricky bit was using a non-copying sort to sort
        the Vector<OwnPtr<MediaQueryExp> > in the MediaQuery constructor.

        * ForwardingHeaders/wtf/NonCopyingSort.h: Added.
        * css/CSSGrammar.y:
        * css/CSSParser.cpp:
        (WebCore::CSSParser::~CSSParser):
        (WebCore::CSSParser::createFloatingMediaQueryExp):
        (WebCore::CSSParser::createFloatingMediaQueryExpList):
        (WebCore::CSSParser::sinkFloatingMediaQueryExpList):
        (WebCore::CSSParser::createFloatingMediaQuery):
        * css/CSSParser.h:
        * css/MediaList.cpp:
        * css/MediaQuery.cpp:
        (WebCore::expressionCompare):
        (WebCore::MediaQuery::MediaQuery):
        (WebCore::MediaQuery::~MediaQuery):
        * css/MediaQuery.h:
        (WebCore::MediaQuery::expressions):
        * css/MediaQueryEvaluator.cpp:
        (WebCore::MediaQueryEvaluator::eval):
        * css/MediaQueryExp.h:
        (WebCore::MediaQueryExp::create):

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

17 files changed:
JavaScriptCore/ChangeLog
JavaScriptCore/GNUmakefile.am
JavaScriptCore/JavaScriptCore.gypi
JavaScriptCore/JavaScriptCore.vcproj/WTF/WTF.vcproj
JavaScriptCore/JavaScriptCore.xcodeproj/project.pbxproj
JavaScriptCore/wtf/NonCopyingSort.h [new file with mode: 0644]
WebCore/ChangeLog
WebCore/ForwardingHeaders/wtf/NonCopyingSort.h [new file with mode: 0644]
WebCore/css/CSSGrammar.y
WebCore/css/CSSParser.cpp
WebCore/css/CSSParser.h
WebCore/css/MediaList.cpp
WebCore/css/MediaQuery.cpp
WebCore/css/MediaQuery.h
WebCore/css/MediaQueryEvaluator.cpp
WebCore/css/MediaQueryExp.cpp
WebCore/css/MediaQueryExp.h

index 4f9944e9bb3512d21df131a7322381fd9923d008..0340a1c3c0586db1522001c40c5834ec98981f25 100644 (file)
@@ -1,3 +1,26 @@
+2010-08-30  Maciej Stachowiak  <mjs@apple.com>
+
+        Reviewed by Darin Adler.
+
+        Handle MediaQueryExp memory management exclusively with smart pointers
+        https://bugs.webkit.org/show_bug.cgi?id=44874
+        
+        Implemented a non-copying sort function to make it possible to sort a Vector
+        of OwnPtrs (which cannot be copied). This is required for the above.
+
+        * wtf/NonCopyingSort.h: Added.
+        (WTF::nonCopyingSort): It's secretly heapsort.
+        (WTF::heapSort): heapsort implementation.
+        (WTF::siftDown): Helper function for heapsort.
+        (WTF::heapify): ditto
+
+        Adjust build systems.
+        
+        * GNUmakefile.am:
+        * JavaScriptCore.gypi:
+        * JavaScriptCore.vcproj/WTF/WTF.vcproj:
+        * JavaScriptCore.xcodeproj/project.pbxproj:
+
 2010-09-08  Zoltan Herczeg  <zherczeg@webkit.org>
 
         Reviewed by Darin Adler.
index 835987012b38ee0d09592f112a5a1e57091125fb..dd2ba21d9d5db92eef75c6c2ed8d3bd405058c4e 100644 (file)
@@ -463,6 +463,7 @@ javascriptcore_sources += \
        JavaScriptCore/wtf/MD5.cpp \
        JavaScriptCore/wtf/MD5.h \
        JavaScriptCore/wtf/MessageQueue.h \
+       JavaScriptCore/wtf/NonCopyingSort.h \
        JavaScriptCore/wtf/Noncopyable.h \
        JavaScriptCore/wtf/NotFound.h \
        JavaScriptCore/wtf/OwnArrayPtr.h \
index 12614d0617a171d032751c05ee67bb28df61b436..462960d51dd6dbe402d5863d208c1328cbc15ace 100644 (file)
             'wtf/MallocZoneSupport.h',
             'wtf/MathExtras.h',
             'wtf/MessageQueue.h',
+            'wtf/NonCopyingSort.h',
             'wtf/Noncopyable.h',
             'wtf/NotFound.h',
             'wtf/OwnArrayPtr.h',
index 7bb2e2a1344933f2414e19eb0dbe86b71c687d40..42a91eb7c698c3c893aa903e06994549a5baf36e 100644 (file)
                        RelativePath="..\..\wtf\MessageQueue.h"\r
                        >\r
                </File>\r
+               <File\r
+                       RelativePath="..\..\wtf\NonCopyingSort.h"\r
+                       >\r
+               </File>\r
                <File\r
                        RelativePath="..\..\wtf\Noncopyable.h"\r
                        >\r
index 36eb45e406dd659613a02175095cb4cc16dc89dc..bee44b6d0afa08f9e7901b84408d7e03d51fb276 100644 (file)
                6507D29E0E871E5E00D7D896 /* JSTypeInfo.h in Headers */ = {isa = PBXBuildFile; fileRef = 6507D2970E871E4A00D7D896 /* JSTypeInfo.h */; settings = {ATTRIBUTES = (Private, ); }; };
                655EB29B10CE2581001A990E /* NodesCodegen.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 655EB29A10CE2581001A990E /* NodesCodegen.cpp */; };
                65DFC93308EA173A00F7300B /* HashTable.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 65DFC92D08EA173A00F7300B /* HashTable.cpp */; };
+               65E1A3DF122B894500B26097 /* NonCopyingSort.h in Headers */ = {isa = PBXBuildFile; fileRef = 65E1A2F4122B880D00B26097 /* NonCopyingSort.h */; settings = {ATTRIBUTES = (Private, ); }; };
                65FDE49C0BDD1D4A00E80111 /* Assertions.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 65E217B808E7EECC0023E5F6 /* Assertions.cpp */; settings = {COMPILER_FLAGS = "-Wno-missing-format-attribute"; }; };
                7E4EE7090EBB7963005934AA /* StructureChain.h in Headers */ = {isa = PBXBuildFile; fileRef = 7E4EE7080EBB7963005934AA /* StructureChain.h */; settings = {ATTRIBUTES = (Private, ); }; };
                7E4EE70F0EBB7A5B005934AA /* StructureChain.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7E4EE70E0EBB7A5B005934AA /* StructureChain.cpp */; };
                65DFC92D08EA173A00F7300B /* HashTable.cpp */ = {isa = PBXFileReference; fileEncoding = 30; indentWidth = 4; lastKnownFileType = sourcecode.cpp.cpp; path = HashTable.cpp; sourceTree = "<group>"; tabWidth = 8; };
                65DFC92E08EA173A00F7300B /* HashTable.h */ = {isa = PBXFileReference; fileEncoding = 30; indentWidth = 4; lastKnownFileType = sourcecode.c.h; path = HashTable.h; sourceTree = "<group>"; tabWidth = 8; };
                65DFC92F08EA173A00F7300B /* HashTraits.h */ = {isa = PBXFileReference; fileEncoding = 30; indentWidth = 4; lastKnownFileType = sourcecode.c.h; path = HashTraits.h; sourceTree = "<group>"; tabWidth = 8; };
+               65E1A2F4122B880D00B26097 /* NonCopyingSort.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NonCopyingSort.h; sourceTree = "<group>"; };
                65E217B708E7EECC0023E5F6 /* Assertions.h */ = {isa = PBXFileReference; fileEncoding = 30; indentWidth = 4; lastKnownFileType = sourcecode.c.h; path = Assertions.h; sourceTree = "<group>"; tabWidth = 8; };
                65E217B808E7EECC0023E5F6 /* Assertions.cpp */ = {isa = PBXFileReference; fileEncoding = 30; indentWidth = 4; lastKnownFileType = sourcecode.cpp.cpp; path = Assertions.cpp; sourceTree = "<group>"; tabWidth = 8; };
                65E217B908E7EECC0023E5F6 /* FastMalloc.cpp */ = {isa = PBXFileReference; fileEncoding = 30; indentWidth = 4; lastKnownFileType = sourcecode.cpp.cpp; path = FastMalloc.cpp; sourceTree = "<group>"; tabWidth = 8; };
                                511FC4C7117EE23D00425272 /* MD5.cpp */,
                                511FC4CA117EE2A800425272 /* MD5.h */,
                                E1EE798B0D6CA53D00FEA3BA /* MessageQueue.h */,
+                               65E1A2F4122B880D00B26097 /* NonCopyingSort.h */,
                                9303F5690991190000AD71B8 /* Noncopyable.h */,
                                C0A2723F0E509F1E00E96E15 /* NotFound.h */,
                                9303F5A409911A5800AD71B8 /* OwnArrayPtr.h */,
                                A76EE6590FAE59D5003F069A /* NativeFunctionWrapper.h in Headers */,
                                7EFF00640EC05A9A00AA7C93 /* NodeInfo.h in Headers */,
                                BC18C43F0E16F5CD00B34460 /* Nodes.h in Headers */,
+                               65E1A3DF122B894500B26097 /* NonCopyingSort.h in Headers */,
                                BC18C4400E16F5CD00B34460 /* Noncopyable.h in Headers */,
                                C0A272630E50A06300E96E15 /* NotFound.h in Headers */,
                                BC18C4410E16F5CD00B34460 /* NumberConstructor.h in Headers */,
diff --git a/JavaScriptCore/wtf/NonCopyingSort.h b/JavaScriptCore/wtf/NonCopyingSort.h
new file mode 100644 (file)
index 0000000..fd611bd
--- /dev/null
@@ -0,0 +1,89 @@
+/*
+ * Copyright (C) 2010 Apple Inc. All Rights Reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE COMPUTER, INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
+ *
+ */
+
+#ifndef WTF_NonCopyingSort_h
+#define WTF_NonCopyingSort_h
+
+namespace WTF {
+
+using std::swap;
+
+template<typename RandomAccessIterator, typename Predicate>
+inline void siftDown(RandomAccessIterator array, ptrdiff_t start, ptrdiff_t end, Predicate compareLess) 
+{
+    ptrdiff_t root = start;
+
+    while (root * 2 + 1 <= end) {
+        ptrdiff_t child = root * 2 + 1;
+        if (child < end && compareLess(array[child], array[child + 1]))
+            child++;
+        
+        if (compareLess(array[root], array[child])) {
+            swap(array[root], array[child]);
+            root = child;
+        } else
+            return;
+    }
+}
+
+template<typename RandomAccessIterator, typename Predicate>
+inline void heapify(RandomAccessIterator array, ptrdiff_t count, Predicate compareLess) 
+{
+    ptrdiff_t start = (count - 2) / 2;
+     
+    while (start >= 0) {
+        siftDown(array, start, count - 1, compareLess);
+        start--;
+    }
+}
+
+template<typename RandomAccessIterator, typename Predicate>
+void heapSort(RandomAccessIterator start, RandomAccessIterator end, Predicate compareLess)
+{
+    ptrdiff_t count = end - start;
+    heapify(start, count, compareLess);
+
+    ptrdiff_t endIndex = count - 1;
+    while (endIndex > 0) {
+        swap(start[endIndex], start[0]);
+        siftDown(start, 0, endIndex - 1, compareLess);
+        endIndex--;
+    }
+}
+
+template<typename RandomAccessIterator, typename Predicate>
+inline void nonCopyingSort(RandomAccessIterator start, RandomAccessIterator end, Predicate compareLess)
+{
+    // heapsort happens to use only swaps, not copies, but the essential thing about
+    // this function is the fact that it does not copy, not the specific algorithm
+    heapSort(start, end, compareLess);
+}
+
+} // namespace WTF
+
+using WTF::nonCopyingSort;
+
+#endif // WTF_NonCopyingSort_h
index 6a2c5f8447ff509cf68a9e67f9496f739bbe698f..837cbb8bc7d7cdbf24dd23b6d255eb9253a0f14c 100644 (file)
@@ -1,3 +1,35 @@
+2010-08-30  Maciej Stachowiak  <mjs@apple.com>
+
+        Reviewed by Darin Adler.
+
+        Handle MediaQueryExp memory management exclusively with smart pointers
+        https://bugs.webkit.org/show_bug.cgi?id=44874
+
+        Gace MediaQueryExp a create function, made the constructor private, and followed
+        the implications. The one tricky bit was using a non-copying sort to sort
+        the Vector<OwnPtr<MediaQueryExp> > in the MediaQuery constructor.
+        
+        * ForwardingHeaders/wtf/NonCopyingSort.h: Added.
+        * css/CSSGrammar.y:
+        * css/CSSParser.cpp:
+        (WebCore::CSSParser::~CSSParser):
+        (WebCore::CSSParser::createFloatingMediaQueryExp):
+        (WebCore::CSSParser::createFloatingMediaQueryExpList):
+        (WebCore::CSSParser::sinkFloatingMediaQueryExpList):
+        (WebCore::CSSParser::createFloatingMediaQuery):
+        * css/CSSParser.h:
+        * css/MediaList.cpp:
+        * css/MediaQuery.cpp:
+        (WebCore::expressionCompare):
+        (WebCore::MediaQuery::MediaQuery):
+        (WebCore::MediaQuery::~MediaQuery):
+        * css/MediaQuery.h:
+        (WebCore::MediaQuery::expressions):
+        * css/MediaQueryEvaluator.cpp:
+        (WebCore::MediaQueryEvaluator::eval):
+        * css/MediaQueryExp.h:
+        (WebCore::MediaQueryExp::create):
+
 2010-09-08  Adam Barth  <abarth@webkit.org>
 
         Reviewed by Maciej Stachowiak.
diff --git a/WebCore/ForwardingHeaders/wtf/NonCopyingSort.h b/WebCore/ForwardingHeaders/wtf/NonCopyingSort.h
new file mode 100644 (file)
index 0000000..d30e61f
--- /dev/null
@@ -0,0 +1,4 @@
+#ifndef WebCore_FWD_NonCopyingSort_h
+#define WebCore_FWD_NonCopyingSort_h
+#include <JavaScriptCore/NonCopyingSort.h>
+#endif
index ec507be03264f3863130c9d48aebce4658060e00..86a2f7cc9834219baba95a83da6e9c6dd8939bb8 100644 (file)
@@ -79,7 +79,7 @@ using namespace HTMLNames;
     MediaQueryExp* mediaQueryExp;
     CSSParserValue value;
     CSSParserValueList* valueList;
-    Vector<MediaQueryExp*>* mediaQueryExpList;
+    Vector<OwnPtr<MediaQueryExp> >* mediaQueryExpList;
     WebKitCSSKeyframeRule* keyframeRule;
     WebKitCSSKeyframesRule* keyframesRule;
     float val;
@@ -627,11 +627,11 @@ media_query_exp_list:
     media_query_exp {
         CSSParser* p = static_cast<CSSParser*>(parser);
         $$ = p->createFloatingMediaQueryExpList();
-        $$->append(p->sinkFloatingMediaQueryExp($1).leakPtr());
+        $$->append(p->sinkFloatingMediaQueryExp($1));
     }
     | media_query_exp_list maybe_space MEDIA_AND maybe_space media_query_exp {
         $$ = $1;
-        $$->append(static_cast<CSSParser*>(parser)->sinkFloatingMediaQueryExp($5).leakPtr());
+        $$->append(static_cast<CSSParser*>(parser)->sinkFloatingMediaQueryExp($5));
     }
     ;
 
index 687235f79053451b58980bb1289b3604c60f3486..2ad329424e22af03a997d0633789d469ea0e8d53 100644 (file)
@@ -172,8 +172,6 @@ CSSParser::~CSSParser()
 
     fastFree(m_data);
 
-    if (m_floatingMediaQueryExpList)
-        deleteAllValues(*m_floatingMediaQueryExpList);
     fastDeleteAllValues(m_floatingSelectors);
     deleteAllValues(m_floatingValueLists);
     deleteAllValues(m_floatingFunctions);
@@ -5273,7 +5271,7 @@ CSSParserValue& CSSParser::sinkFloatingValue(CSSParserValue& value)
 
 MediaQueryExp* CSSParser::createFloatingMediaQueryExp(const AtomicString& mediaFeature, CSSParserValueList* values)
 {
-    m_floatingMediaQueryExp = adoptPtr(new MediaQueryExp(mediaFeature, values));
+    m_floatingMediaQueryExp = MediaQueryExp::create(mediaFeature, values);
     return m_floatingMediaQueryExp.get();
 }
 
@@ -5283,27 +5281,25 @@ PassOwnPtr<MediaQueryExp> CSSParser::sinkFloatingMediaQueryExp(MediaQueryExp* ex
     return m_floatingMediaQueryExp.release();
 }
 
-Vector<MediaQueryExp*>* CSSParser::createFloatingMediaQueryExpList()
+Vector<OwnPtr<MediaQueryExp> >* CSSParser::createFloatingMediaQueryExpList()
 {
-    if (m_floatingMediaQueryExpList)
-        deleteAllValues(*m_floatingMediaQueryExpList);
-    m_floatingMediaQueryExpList = adoptPtr(new Vector<MediaQueryExp*>);
+    m_floatingMediaQueryExpList = adoptPtr(new Vector<OwnPtr<MediaQueryExp> >);
     return m_floatingMediaQueryExpList.get();
 }
 
-PassOwnPtr<Vector<MediaQueryExp*> > CSSParser::sinkFloatingMediaQueryExpList(Vector<MediaQueryExp*>* list)
+PassOwnPtr<Vector<OwnPtr<MediaQueryExp> > > CSSParser::sinkFloatingMediaQueryExpList(Vector<OwnPtr<MediaQueryExp> >* list)
 {
     ASSERT_UNUSED(list, list == m_floatingMediaQueryExpList);
     return m_floatingMediaQueryExpList.release();
 }
 
-MediaQuery* CSSParser::createFloatingMediaQuery(MediaQuery::Restrictor restrictor, const String& mediaType, PassOwnPtr<Vector<MediaQueryExp*> > expressions)
+MediaQuery* CSSParser::createFloatingMediaQuery(MediaQuery::Restrictor restrictor, const String& mediaType, PassOwnPtr<Vector<OwnPtr<MediaQueryExp> > > expressions)
 {
     m_floatingMediaQuery = adoptPtr(new MediaQuery(restrictor, mediaType, expressions));
     return m_floatingMediaQuery.get();
 }
 
-MediaQuery* CSSParser::createFloatingMediaQuery(PassOwnPtr<Vector<MediaQueryExp*> > expressions)
+MediaQuery* CSSParser::createFloatingMediaQuery(PassOwnPtr<Vector<OwnPtr<MediaQueryExp> > > expressions)
 {
     return createFloatingMediaQuery(MediaQuery::None, "all", expressions);
 }
index 6211e628b9664e67afb75b08a1809c0667336574..e840a70e4582e1d17014afc63c823a02217b304d 100644 (file)
@@ -195,10 +195,10 @@ namespace WebCore {
 
         MediaQueryExp* createFloatingMediaQueryExp(const AtomicString&, CSSParserValueList*);
         PassOwnPtr<MediaQueryExp> sinkFloatingMediaQueryExp(MediaQueryExp*);
-        Vector<MediaQueryExp*>* createFloatingMediaQueryExpList();
-        PassOwnPtr<Vector<MediaQueryExp*> > sinkFloatingMediaQueryExpList(Vector<MediaQueryExp*>*);
-        MediaQuery* createFloatingMediaQuery(MediaQuery::Restrictor, const String&, PassOwnPtr<Vector<MediaQueryExp*> >);
-        MediaQuery* createFloatingMediaQuery(PassOwnPtr<Vector<MediaQueryExp*> >);
+        Vector<OwnPtr<MediaQueryExp> >* createFloatingMediaQueryExpList();
+        PassOwnPtr<Vector<OwnPtr<MediaQueryExp> > > sinkFloatingMediaQueryExpList(Vector<OwnPtr<MediaQueryExp> >*);
+        MediaQuery* createFloatingMediaQuery(MediaQuery::Restrictor, const String&, PassOwnPtr<Vector<OwnPtr<MediaQueryExp> > >);
+        MediaQuery* createFloatingMediaQuery(PassOwnPtr<Vector<OwnPtr<MediaQueryExp> > >);
         PassOwnPtr<MediaQuery> sinkFloatingMediaQuery(MediaQuery*);
 
         void addNamespace(const AtomicString& prefix, const AtomicString& uri);
@@ -303,7 +303,7 @@ namespace WebCore {
 
         OwnPtr<MediaQuery> m_floatingMediaQuery;
         OwnPtr<MediaQueryExp> m_floatingMediaQueryExp;
-        OwnPtr<Vector<MediaQueryExp*> > m_floatingMediaQueryExpList;
+        OwnPtr<Vector<OwnPtr<MediaQueryExp> > > m_floatingMediaQueryExpList;
 
         Vector<CSSSelector*> m_reusableSelectorVector;
 
index e67c9c78c3f3ce5f6ec2657d5d63f0a9797e881f..81f87122d829520ba18300fc58934a3cf6aa9592 100644 (file)
@@ -25,6 +25,7 @@
 #include "CSSStyleSheet.h"
 #include "ExceptionCode.h"
 #include "MediaQuery.h"
+#include "MediaQueryExp.h"
 
 namespace WebCore {
 
index b71706caed356505c377eb694a552b7ea52834e0..77a79ad830d15da8ef9204a25b907fccb5fe6446 100644 (file)
@@ -31,8 +31,7 @@
 
 #include "MediaQueryExp.h"
 #include "StringBuilder.h"
-
-#include <algorithm>
+#include <wtf/NonCopyingSort.h>
 
 namespace WebCore {
 
@@ -70,23 +69,24 @@ String MediaQuery::serialize() const
     return result.toString();
 }
 
-static bool expressionCompare(const MediaQueryExp* a, const MediaQueryExp* b)
+static bool expressionCompare(const OwnPtr<MediaQueryExp>& a, const OwnPtr<MediaQueryExp>& b) 
 {
     return codePointCompare(a->serialize(), b->serialize()) < 0;
 }
 
-MediaQuery::MediaQuery(Restrictor r, const String& mediaType, PassOwnPtr<Vector<MediaQueryExp*> > exprs)
+
+MediaQuery::MediaQuery(Restrictor r, const String& mediaType, PassOwnPtr<Vector<OwnPtr<MediaQueryExp> > > exprs)
     : m_restrictor(r)
     , m_mediaType(mediaType.lower())
     , m_expressions(exprs)
     , m_ignored(false)
 {
     if (!m_expressions) {
-        m_expressions = new Vector<MediaQueryExp*>;
+        m_expressions = adoptPtr(new Vector<OwnPtr<MediaQueryExp> >);
         return;
     }
 
-    std::sort(m_expressions->begin(), m_expressions->end(), expressionCompare);
+    nonCopyingSort(m_expressions->begin(), m_expressions->end(), expressionCompare);
 
     // remove all duplicated expressions
     String key;
@@ -95,19 +95,16 @@ MediaQuery::MediaQuery(Restrictor r, const String& mediaType, PassOwnPtr<Vector<
         // if not all of the expressions is valid the media query must be ignored.
         if (!m_ignored)
             m_ignored = !m_expressions->at(i)->isValid();
-
-        if (m_expressions->at(i)->serialize() == key) {
-            MediaQueryExp* item = m_expressions->at(i);
+        if (m_expressions->at(i)->serialize() == key)
             m_expressions->remove(i);
-            delete item;
-        } else
+        else
             key = m_expressions->at(i)->serialize();
     }
 }
 
 MediaQuery::~MediaQuery()
 {
-    deleteAllValues(*m_expressions);
 }
 
 // http://dev.w3.org/csswg/cssom/#compare-media-queries
index 3eea3b25f7d48525116bdb26d106bc471b48fa31..281009b57a0c8a3acb58ee3a3031d9664c9c28f6 100644 (file)
@@ -43,11 +43,11 @@ public:
         Only, Not, None
     };
 
-    MediaQuery(Restrictor, const String& mediaType, PassOwnPtr<Vector<MediaQueryExp*> > exprs);
+    MediaQuery(Restrictor, const String& mediaType, PassOwnPtr<Vector<OwnPtr<MediaQueryExp> > > exprs);
     ~MediaQuery();
 
     Restrictor restrictor() const { return m_restrictor; }
-    const Vector<MediaQueryExp*>* expressions() const { return m_expressions.get(); }
+    const Vector<OwnPtr<MediaQueryExp> >* expressions() const { return m_expressions.get(); }
     String mediaType() const { return m_mediaType; }
     bool operator==(const MediaQuery& other) const;
     String cssText() const;
@@ -56,7 +56,7 @@ public:
  private:
     Restrictor m_restrictor;
     String m_mediaType;
-    OwnPtr<Vector<MediaQueryExp*> > m_expressions;
+    OwnPtr<Vector<OwnPtr<MediaQueryExp> > > m_expressions;
     bool m_ignored;
     String m_serializationCache;
 
index 0b5507ef94266cade032693e3c4cff95cff72bd4..c757d5159ea257985ada79c9d52741f14eb75f4e 100644 (file)
@@ -148,14 +148,14 @@ bool MediaQueryEvaluator::eval(const MediaList* mediaList, CSSStyleSelector* sty
             continue;
 
         if (mediaTypeMatch(query->mediaType())) {
-            const Vector<MediaQueryExp*>* exps = query->expressions();
+            const Vector<OwnPtr<MediaQueryExp> >* exps = query->expressions();
             // iterate through expressions, stop if any of them eval to false
             // (AND semantics)
             size_t j = 0;
             for (; j < exps->size(); ++j) {
-                bool exprResult = eval(exps->at(j));
+                bool exprResult = eval(exps->at(j).get());
                 if (styleSelector && exps->at(j)->isViewportDependent())
-                    styleSelector->addViewportDependentMediaQueryResult(exps->at(j), exprResult);
+                    styleSelector->addViewportDependentMediaQueryResult(exps->at(j).get(), exprResult);
                 if (!exprResult)
                     break;
             }
index a93ddcce579423574bdd3979f80c4ceb0bb0c4fc..36a155ea643d598ae7a209bf0f49f128bc8aa98e 100644 (file)
@@ -36,7 +36,7 @@
 
 namespace WebCore {
 
-MediaQueryExp::MediaQueryExp(const AtomicString& mediaFeature, CSSParserValueList* valueList)
+inline MediaQueryExp::MediaQueryExp(const AtomicString& mediaFeature, CSSParserValueList* valueList)
     : m_mediaFeature(mediaFeature)
     , m_value(0)
     , m_isValid(true)
@@ -80,6 +80,12 @@ MediaQueryExp::MediaQueryExp(const AtomicString& mediaFeature, CSSParserValueLis
     }
 }
 
+
+PassOwnPtr<MediaQueryExp> MediaQueryExp::create(const AtomicString& mediaFeature, CSSParserValueList* values)
+{
+    return adoptPtr(new MediaQueryExp(mediaFeature, values));
+}
+
 MediaQueryExp::~MediaQueryExp()
 {
 }
index 4b42611b4ab192006ccddd4eb600e1998e4e0f59..72d3fffc0eaf4c5e7643b931f625bef6dd5117d2 100644 (file)
@@ -31,6 +31,7 @@
 
 #include "CSSValue.h"
 #include "MediaFeatureNames.h"
+#include <wtf/PassOwnPtr.h>
 #include <wtf/RefPtr.h>
 #include <wtf/text/AtomicString.h>
 
@@ -39,7 +40,7 @@ class CSSParserValueList;
 
 class MediaQueryExp : public FastAllocBase {
 public:
-    MediaQueryExp(const AtomicString& mediaFeature, CSSParserValueList* values);
+    static PassOwnPtr<MediaQueryExp> create(const AtomicString& mediaFeature, CSSParserValueList* values);
     ~MediaQueryExp();
 
     AtomicString mediaFeature() const { return m_mediaFeature; }
@@ -69,6 +70,8 @@ public:
     String serialize() const;
 
 private:
+    MediaQueryExp(const AtomicString& mediaFeature, CSSParserValueList* values);
+
     AtomicString m_mediaFeature;
     RefPtr<CSSValue> m_value;
     bool m_isValid;