Title: [237329] trunk/Source
Revision
237329
Author
[email protected]
Date
2018-10-22 14:05:02 -0700 (Mon, 22 Oct 2018)

Log Message

Deque's contains() and findIf() should be const
https://bugs.webkit.org/show_bug.cgi?id=190796

Reviewed by Antti Koivisto.

Source/WebKit:

Mark method as const now that Deque's implementation allows it to be.

* UIProcess/WebProcessPool.cpp:
(WebKit::WebProcessPool::hasSuspendedPageProxyFor const):
(WebKit::WebProcessPool::hasSuspendedPageProxyFor): Deleted.
* UIProcess/WebProcessPool.h:

Source/WTF:

Deque's contains() and findIf() should be const as they do not modify the container.

* wtf/Deque.h:
(WTF::inlineCapacity>::findIf):
(WTF::inlineCapacity>::findIf const):
(WTF::inlineCapacity>::contains const):
(WTF::inlineCapacity>::contains): Deleted.

Modified Paths

Diff

Modified: trunk/Source/WTF/ChangeLog (237328 => 237329)


--- trunk/Source/WTF/ChangeLog	2018-10-22 20:12:07 UTC (rev 237328)
+++ trunk/Source/WTF/ChangeLog	2018-10-22 21:05:02 UTC (rev 237329)
@@ -1,3 +1,18 @@
+2018-10-22  Chris Dumez  <[email protected]>
+
+        Deque's contains() and findIf() should be const
+        https://bugs.webkit.org/show_bug.cgi?id=190796
+
+        Reviewed by Antti Koivisto.
+
+        Deque's contains() and findIf() should be const as they do not modify the container.
+
+        * wtf/Deque.h:
+        (WTF::inlineCapacity>::findIf):
+        (WTF::inlineCapacity>::findIf const):
+        (WTF::inlineCapacity>::contains const):
+        (WTF::inlineCapacity>::contains): Deleted.
+
 2018-10-18  Alicia Boya GarcĂ­a  <[email protected]>
 
         [Media] Use nanoseconds as MaximumTimeScale

Modified: trunk/Source/WTF/wtf/Deque.h (237328 => 237329)


--- trunk/Source/WTF/wtf/Deque.h	2018-10-22 20:12:07 UTC (rev 237328)
+++ trunk/Source/WTF/wtf/Deque.h	2018-10-22 21:05:02 UTC (rev 237329)
@@ -32,6 +32,7 @@
 // FIXME: Could move what Vector and Deque share into a separate file.
 // Deque doesn't actually use Vector.
 
+#include <algorithm>
 #include <iterator>
 #include <wtf/Vector.h>
 
@@ -75,7 +76,7 @@
     const_reverse_iterator rbegin() const { return const_reverse_iterator(end()); }
     const_reverse_iterator rend() const { return const_reverse_iterator(begin()); }
     
-    template<typename U> bool contains(const U&);
+    template<typename U> bool contains(const U&) const;
 
     T& first() { ASSERT(m_start != m_end); return m_buffer.buffer()[m_start]; }
     const T& first() const { ASSERT(m_start != m_end); return m_buffer.buffer()[m_start]; }
@@ -113,8 +114,8 @@
 
     void clear();
 
-    template<typename Predicate>
-    iterator findIf(Predicate&&);
+    template<typename Predicate> iterator findIf(const Predicate&);
+    template<typename Predicate> const_iterator findIf(const Predicate&) const;
 
 private:
     friend class DequeIteratorBase<T, inlineCapacity>;
@@ -394,17 +395,19 @@
 
 template<typename T, size_t inlineCapacity>
 template<typename Predicate>
-inline auto Deque<T, inlineCapacity>::findIf(Predicate&& predicate) -> iterator
+inline auto Deque<T, inlineCapacity>::findIf(const Predicate& predicate) -> iterator
 {
-    iterator end_iterator = end();
-    for (iterator it = begin(); it != end_iterator; ++it) {
-        if (predicate(*it))
-            return it;
-    }
-    return end_iterator;
+    return std::find_if(begin(), end(), predicate);
 }
 
 template<typename T, size_t inlineCapacity>
+template<typename Predicate>
+inline auto Deque<T, inlineCapacity>::findIf(const Predicate& predicate) const -> const_iterator
+{
+    return std::find_if(begin(), end(), predicate);
+}
+
+template<typename T, size_t inlineCapacity>
 inline void Deque<T, inlineCapacity>::expandCapacityIfNeeded()
 {
     if (m_start) {
@@ -440,13 +443,10 @@
 
 template<typename T, size_t inlineCapacity>
 template<typename U>
-bool Deque<T, inlineCapacity>::contains(const U& searchValue)
+bool Deque<T, inlineCapacity>::contains(const U& searchValue) const
 {
-    for (auto& value : *this) {
-        if (value == searchValue)
-            return true;
-    }
-    return false;
+    auto endIterator = end();
+    return std::find(begin(), endIterator, searchValue) != endIterator;
 }
 
 template<typename T, size_t inlineCapacity>

Modified: trunk/Source/WebKit/ChangeLog (237328 => 237329)


--- trunk/Source/WebKit/ChangeLog	2018-10-22 20:12:07 UTC (rev 237328)
+++ trunk/Source/WebKit/ChangeLog	2018-10-22 21:05:02 UTC (rev 237329)
@@ -1,3 +1,17 @@
+2018-10-22  Chris Dumez  <[email protected]>
+
+        Deque's contains() and findIf() should be const
+        https://bugs.webkit.org/show_bug.cgi?id=190796
+
+        Reviewed by Antti Koivisto.
+
+        Mark method as const now that Deque's implementation allows it to be.
+
+        * UIProcess/WebProcessPool.cpp:
+        (WebKit::WebProcessPool::hasSuspendedPageProxyFor const):
+        (WebKit::WebProcessPool::hasSuspendedPageProxyFor): Deleted.
+        * UIProcess/WebProcessPool.h:
+
 2018-10-19  Brent Fulgham  <[email protected]>
 
         Allow WebContent process to check some file system features

Modified: trunk/Source/WebKit/UIProcess/WebProcessPool.cpp (237328 => 237329)


--- trunk/Source/WebKit/UIProcess/WebProcessPool.cpp	2018-10-22 20:12:07 UTC (rev 237328)
+++ trunk/Source/WebKit/UIProcess/WebProcessPool.cpp	2018-10-22 21:05:02 UTC (rev 237329)
@@ -2227,7 +2227,7 @@
     });
 }
 
-bool WebProcessPool::hasSuspendedPageProxyFor(WebProcessProxy& process)
+bool WebProcessPool::hasSuspendedPageProxyFor(WebProcessProxy& process) const
 {
     return m_suspendedPages.findIf([&process](auto& suspendedPage) {
         return &suspendedPage->process() == &process;

Modified: trunk/Source/WebKit/UIProcess/WebProcessPool.h (237328 => 237329)


--- trunk/Source/WebKit/UIProcess/WebProcessPool.h	2018-10-22 20:12:07 UTC (rev 237328)
+++ trunk/Source/WebKit/UIProcess/WebProcessPool.h	2018-10-22 21:05:02 UTC (rev 237329)
@@ -446,7 +446,7 @@
     void addSuspendedPageProxy(std::unique_ptr<SuspendedPageProxy>&&);
     void removeAllSuspendedPageProxiesForPage(WebPageProxy&);
     std::unique_ptr<SuspendedPageProxy> takeSuspendedPageProxy(SuspendedPageProxy&);
-    bool hasSuspendedPageProxyFor(WebProcessProxy&);
+    bool hasSuspendedPageProxyFor(WebProcessProxy&) const;
 
     void didReachGoodTimeToPrewarm();
 
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to