Test the waters and begin using lambdas
authorandersca@apple.com <andersca@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 23 Sep 2013 23:53:28 +0000 (23:53 +0000)
committerandersca@apple.com <andersca@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 23 Sep 2013 23:53:28 +0000 (23:53 +0000)
https://bugs.webkit.org/show_bug.cgi?id=121809

Reviewed by Andreas Kling.

Source/WebCore:

Use lambdas instead of static functions and function objects.

* css/MediaQuery.cpp:
(WebCore::MediaQuery::MediaQuery):
* dom/MutationObserver.cpp:
(WebCore::MutationObserver::deliverAllMutations):
* page/CaptionUserPreferences.cpp:
(WebCore::CaptionUserPreferences::sortedTrackListForMenu):

Source/WTF:

* wtf/ListDump.h:
(WTF::sortedListDump):
Use std::less instead of a custom lessThan function.

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

Source/WTF/ChangeLog
Source/WTF/wtf/ListDump.h
Source/WebCore/ChangeLog
Source/WebCore/css/MediaQuery.cpp
Source/WebCore/dom/MutationObserver.cpp
Source/WebCore/page/CaptionUserPreferences.cpp

index 8e9abf2..0cf9738 100644 (file)
@@ -1,5 +1,16 @@
 2013-09-23  Anders Carlsson  <andersca@apple.com>
 
+        Test the waters and begin using lambdas
+        https://bugs.webkit.org/show_bug.cgi?id=121809
+
+        Reviewed by Andreas Kling.
+
+        * wtf/ListDump.h:
+        (WTF::sortedListDump):
+        Use std::less instead of a custom lessThan function.
+
+2013-09-23  Anders Carlsson  <andersca@apple.com>
+
         ListHashSet::removeLast should only remove one element.
         
         * wtf/ListHashSet.h:
index a1344e5..7e996a3 100644 (file)
@@ -94,15 +94,9 @@ CString sortedListDump(const T& list, const Comparator& comparator, const char*
 }
 
 template<typename T>
-inline bool lessThan(const T& a, const T& b)
-{
-    return a < b;
-}
-
-template<typename T>
 CString sortedListDump(const T& list, const char* comma = ", ")
 {
-    return sortedListDump(list, lessThan<typename T::ValueType>, comma);
+    return sortedListDump(list, std::less<typename T::ValueType>(), comma);
 }
 
 template<typename T>
index aee5ad0..1b2eb82 100644 (file)
@@ -1,3 +1,19 @@
+2013-09-23  Anders Carlsson  <andersca@apple.com>
+
+        Test the waters and begin using lambdas
+        https://bugs.webkit.org/show_bug.cgi?id=121809
+
+        Reviewed by Andreas Kling.
+
+        Use lambdas instead of static functions and function objects.
+        
+        * css/MediaQuery.cpp:
+        (WebCore::MediaQuery::MediaQuery):
+        * dom/MutationObserver.cpp:
+        (WebCore::MutationObserver::deliverAllMutations):
+        * page/CaptionUserPreferences.cpp:
+        (WebCore::CaptionUserPreferences::sortedTrackListForMenu):
+
 2013-09-23  Patrick Gansterer  <paroga@webkit.org>
 
         [WIN] Add implementation for WebCore::readFromFile()
index fe0f9d5..39304d8 100644 (file)
@@ -72,11 +72,6 @@ String MediaQuery::serialize() const
     return result.toString();
 }
 
-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<ExpressionVector> exprs)
     : m_restrictor(r)
     , m_mediaType(mediaType.lower())
@@ -88,7 +83,9 @@ MediaQuery::MediaQuery(Restrictor r, const String& mediaType, PassOwnPtr<Express
         return;
     }
 
-    std::sort(m_expressions->begin(), m_expressions->end(), expressionCompare);
+    std::sort(m_expressions->begin(), m_expressions->end(), [](const OwnPtr<MediaQueryExp>& a, const OwnPtr<MediaQueryExp>& b) {
+        return codePointCompare(a->serialize(), b->serialize()) < 0;
+    });
 
     // remove all duplicated expressions
     String key;
index d4a6e6e..1ff26b1 100644 (file)
@@ -48,13 +48,6 @@ namespace WebCore {
 
 static unsigned s_observerPriority = 0;
 
-struct MutationObserver::ObserverLessThan {
-    bool operator()(const RefPtr<MutationObserver>& lhs, const RefPtr<MutationObserver>& rhs)
-    {
-        return lhs->m_priority < rhs->m_priority;
-    }
-};
-
 PassRefPtr<MutationObserver> MutationObserver::create(PassRefPtr<MutationCallback> callback)
 {
     ASSERT(isMainThread());
@@ -231,7 +224,10 @@ void MutationObserver::deliverAllMutations()
         Vector<RefPtr<MutationObserver> > observers;
         copyToVector(activeMutationObservers(), observers);
         activeMutationObservers().clear();
-        std::sort(observers.begin(), observers.end(), ObserverLessThan());
+        std::sort(observers.begin(), observers.end(), [](const RefPtr<MutationObserver>& lhs, const RefPtr<MutationObserver>& rhs) {
+            return lhs->m_priority < rhs->m_priority;
+        });
+
         for (size_t i = 0; i < observers.size(); ++i) {
             if (observers[i]->canDeliver())
                 observers[i]->deliver();
index 2375ed3..f8c4d09 100644 (file)
@@ -173,11 +173,6 @@ String CaptionUserPreferences::displayNameForTrack(TextTrack* track) const
     return trackDisplayName(track);
 }
     
-static bool textTrackCompare(const RefPtr<TextTrack>& a, const RefPtr<TextTrack>& b)
-{
-    return codePointCompare(trackDisplayName(a.get()), trackDisplayName(b.get())) < 0;
-}
-
 Vector<RefPtr<TextTrack>> CaptionUserPreferences::sortedTrackListForMenu(TextTrackList* trackList)
 {
     ASSERT(trackList);
@@ -187,7 +182,9 @@ Vector<RefPtr<TextTrack>> CaptionUserPreferences::sortedTrackListForMenu(TextTra
     for (unsigned i = 0, length = trackList->length(); i < length; ++i)
         tracksForMenu.append(trackList->item(i));
 
-    std::sort(tracksForMenu.begin(), tracksForMenu.end(), textTrackCompare);
+    std::sort(tracksForMenu.begin(), tracksForMenu.end(), [](const RefPtr<TextTrack>& a, const RefPtr<TextTrack>& b) {
+        return codePointCompare(trackDisplayName(a.get()), trackDisplayName(b.get())) < 0;
+    });
 
     tracksForMenu.insert(0, TextTrack::captionMenuOffItem());
     tracksForMenu.insert(1, TextTrack::captionMenuAutomaticItem());