[SCM] WebKit Debian packaging branch, debian/experimental, updated. upstream/1.3.3-9427-gc2be6fc

mjs at apple.com mjs at apple.com
Wed Dec 22 13:10:54 UTC 2010


The following commit has been merged in the debian/experimental branch:
commit d3a360f622518aceedff02fc855658efc19b5bb4
Author: mjs at apple.com <mjs at apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Date:   Wed Sep 8 11:08:08 2010 +0000

    2010-08-30  Maciej Stachowiak  <mjs at 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-08-30  Maciej Stachowiak  <mjs at 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

diff --git a/JavaScriptCore/ChangeLog b/JavaScriptCore/ChangeLog
index 4f9944e..0340a1c 100644
--- a/JavaScriptCore/ChangeLog
+++ b/JavaScriptCore/ChangeLog
@@ -1,3 +1,26 @@
+2010-08-30  Maciej Stachowiak  <mjs at 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 at webkit.org>
 
         Reviewed by Darin Adler.
diff --git a/JavaScriptCore/GNUmakefile.am b/JavaScriptCore/GNUmakefile.am
index 8359870..dd2ba21 100644
--- a/JavaScriptCore/GNUmakefile.am
+++ b/JavaScriptCore/GNUmakefile.am
@@ -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 \
diff --git a/JavaScriptCore/JavaScriptCore.gypi b/JavaScriptCore/JavaScriptCore.gypi
index 12614d0..462960d 100644
--- a/JavaScriptCore/JavaScriptCore.gypi
+++ b/JavaScriptCore/JavaScriptCore.gypi
@@ -394,6 +394,7 @@
             'wtf/MallocZoneSupport.h',
             'wtf/MathExtras.h',
             'wtf/MessageQueue.h',
+            'wtf/NonCopyingSort.h',
             'wtf/Noncopyable.h',
             'wtf/NotFound.h',
             'wtf/OwnArrayPtr.h',
diff --git a/JavaScriptCore/JavaScriptCore.vcproj/WTF/WTF.vcproj b/JavaScriptCore/JavaScriptCore.vcproj/WTF/WTF.vcproj
index 7bb2e2a..42a91eb 100644
--- a/JavaScriptCore/JavaScriptCore.vcproj/WTF/WTF.vcproj
+++ b/JavaScriptCore/JavaScriptCore.vcproj/WTF/WTF.vcproj
@@ -405,6 +405,10 @@
 			>
 		</File>
 		<File
+			RelativePath="..\..\wtf\NonCopyingSort.h"
+			>
+		</File>
+		<File
 			RelativePath="..\..\wtf\Noncopyable.h"
 			>
 		</File>
diff --git a/JavaScriptCore/JavaScriptCore.xcodeproj/project.pbxproj b/JavaScriptCore/JavaScriptCore.xcodeproj/project.pbxproj
index 36eb45e..bee44b6 100644
--- a/JavaScriptCore/JavaScriptCore.xcodeproj/project.pbxproj
+++ b/JavaScriptCore/JavaScriptCore.xcodeproj/project.pbxproj
@@ -188,6 +188,7 @@
 		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 */; };
@@ -775,6 +776,7 @@
 		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; };
@@ -1492,6 +1494,7 @@
 				511FC4C7117EE23D00425272 /* MD5.cpp */,
 				511FC4CA117EE2A800425272 /* MD5.h */,
 				E1EE798B0D6CA53D00FEA3BA /* MessageQueue.h */,
+				65E1A2F4122B880D00B26097 /* NonCopyingSort.h */,
 				9303F5690991190000AD71B8 /* Noncopyable.h */,
 				C0A2723F0E509F1E00E96E15 /* NotFound.h */,
 				9303F5A409911A5800AD71B8 /* OwnArrayPtr.h */,
@@ -2166,6 +2169,7 @@
 				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
index 0000000..fd611bd
--- /dev/null
+++ b/JavaScriptCore/wtf/NonCopyingSort.h
@@ -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
diff --git a/WebCore/ChangeLog b/WebCore/ChangeLog
index 6a2c5f8..837cbb8 100644
--- a/WebCore/ChangeLog
+++ b/WebCore/ChangeLog
@@ -1,3 +1,35 @@
+2010-08-30  Maciej Stachowiak  <mjs at 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 at webkit.org>
 
         Reviewed by Maciej Stachowiak.
diff --git a/WebCore/ForwardingHeaders/wtf/NonCopyingSort.h b/WebCore/ForwardingHeaders/wtf/NonCopyingSort.h
new file mode 100644
index 0000000..d30e61f
--- /dev/null
+++ b/WebCore/ForwardingHeaders/wtf/NonCopyingSort.h
@@ -0,0 +1,4 @@
+#ifndef WebCore_FWD_NonCopyingSort_h
+#define WebCore_FWD_NonCopyingSort_h
+#include <JavaScriptCore/NonCopyingSort.h>
+#endif
diff --git a/WebCore/css/CSSGrammar.y b/WebCore/css/CSSGrammar.y
index ec507be..86a2f7c 100644
--- a/WebCore/css/CSSGrammar.y
+++ b/WebCore/css/CSSGrammar.y
@@ -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));
     }
     ;
 
diff --git a/WebCore/css/CSSParser.cpp b/WebCore/css/CSSParser.cpp
index 687235f..2ad3294 100644
--- a/WebCore/css/CSSParser.cpp
+++ b/WebCore/css/CSSParser.cpp
@@ -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);
 }
diff --git a/WebCore/css/CSSParser.h b/WebCore/css/CSSParser.h
index 6211e62..e840a70 100644
--- a/WebCore/css/CSSParser.h
+++ b/WebCore/css/CSSParser.h
@@ -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;
 
diff --git a/WebCore/css/MediaList.cpp b/WebCore/css/MediaList.cpp
index e67c9c7..81f8712 100644
--- a/WebCore/css/MediaList.cpp
+++ b/WebCore/css/MediaList.cpp
@@ -25,6 +25,7 @@
 #include "CSSStyleSheet.h"
 #include "ExceptionCode.h"
 #include "MediaQuery.h"
+#include "MediaQueryExp.h"
 
 namespace WebCore {
 
diff --git a/WebCore/css/MediaQuery.cpp b/WebCore/css/MediaQuery.cpp
index b71706c..77a79ad 100644
--- a/WebCore/css/MediaQuery.cpp
+++ b/WebCore/css/MediaQuery.cpp
@@ -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
diff --git a/WebCore/css/MediaQuery.h b/WebCore/css/MediaQuery.h
index 3eea3b2..281009b 100644
--- a/WebCore/css/MediaQuery.h
+++ b/WebCore/css/MediaQuery.h
@@ -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;
 
diff --git a/WebCore/css/MediaQueryEvaluator.cpp b/WebCore/css/MediaQueryEvaluator.cpp
index 0b5507e..c757d51 100644
--- a/WebCore/css/MediaQueryEvaluator.cpp
+++ b/WebCore/css/MediaQueryEvaluator.cpp
@@ -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;
             }
diff --git a/WebCore/css/MediaQueryExp.cpp b/WebCore/css/MediaQueryExp.cpp
index a93ddcc..36a155e 100644
--- a/WebCore/css/MediaQueryExp.cpp
+++ b/WebCore/css/MediaQueryExp.cpp
@@ -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()
 {
 }
diff --git a/WebCore/css/MediaQueryExp.h b/WebCore/css/MediaQueryExp.h
index 4b42611..72d3fff 100644
--- a/WebCore/css/MediaQueryExp.h
+++ b/WebCore/css/MediaQueryExp.h
@@ -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;

-- 
WebKit Debian packaging



More information about the Pkg-webkit-commits mailing list