Title: [161770] trunk/Source
Revision
161770
Author
wei...@apple.com
Date
2014-01-11 11:17:55 -0800 (Sat, 11 Jan 2014)

Log Message

Clean up iterator filter / iterator range code
https://bugs.webkit.org/show_bug.cgi?id=126817

Reviewed by Anders Carlsson.

Source/WebKit2: 

* Shared/APIArray.h:
Update elementsOfType() to use combination of FilterIterator and TransformIterator
(now that FilterIterator no longer has a transform predicate) and make use of the 
makeFoo() helpers.

Source/WTF: 

- Renames IteratorPair to IteratorRange.
- Splits FilterIterator into FilterIterator (which now only filters) and
  TransformIterator (which does the transform part of the old FilterIterator).
  Move both of these to IteratorAdaptors.h

* GNUmakefile.list.am:
* WTF.vcxproj/WTF.vcxproj:
* WTF.vcxproj/WTF.vcxproj.filters:
* WTF.xcodeproj/project.pbxproj:
* wtf/CMakeLists.txt:
* wtf/FilterIterator.h: Removed.
Add/remove files.

* wtf/HashMap.h:
(WTF::HashMap::keys):
(WTF::HashMap::values):
* wtf/RefPtrHashMap.h:
Update for rename to IteratorRange. Simplify by using makeIteratorRange().

* wtf/IteratorAdaptors.h: Copied from wtf/FilterIterator.h.
(WTF::FilterIterator::FilterIterator):
(WTF::FilterIterator::operator*):
(WTF::makeFilterIterator):
(WTF::TransformIterator::TransformIterator):
(WTF::TransformIterator::operator++):
(WTF::TransformIterator::operator*):
(WTF::TransformIterator::operator==):
(WTF::TransformIterator::operator!=):
(WTF::makeTransformIterator):
Split up filtering and transforming. Add makeFilterIterator() and makeTransformIterator()
helpers.

* wtf/IteratorPair.h: Removed.
* wtf/IteratorRange.h: Copied from wtf/IteratorPair.h.
(WTF::IteratorRange::IteratorRange):
(WTF::makeIteratorRange):
Renamed to IteratorRange and adds makeIteratorRange() helper.

Modified Paths

Added Paths

Removed Paths

Diff

Modified: trunk/Source/WTF/ChangeLog (161769 => 161770)


--- trunk/Source/WTF/ChangeLog	2014-01-11 19:16:14 UTC (rev 161769)
+++ trunk/Source/WTF/ChangeLog	2014-01-11 19:17:55 UTC (rev 161770)
@@ -1,3 +1,48 @@
+2014-01-11  Sam Weinig  <s...@webkit.org>
+
+        Clean up iterator filter / iterator range code
+        https://bugs.webkit.org/show_bug.cgi?id=126817
+
+        Reviewed by Anders Carlsson.
+
+        - Renames IteratorPair to IteratorRange.
+        - Splits FilterIterator into FilterIterator (which now only filters) and
+          TransformIterator (which does the transform part of the old FilterIterator).
+          Move both of these to IteratorAdaptors.h
+
+        * GNUmakefile.list.am:
+        * WTF.vcxproj/WTF.vcxproj:
+        * WTF.vcxproj/WTF.vcxproj.filters:
+        * WTF.xcodeproj/project.pbxproj:
+        * wtf/CMakeLists.txt:
+        * wtf/FilterIterator.h: Removed.
+        Add/remove files.
+
+        * wtf/HashMap.h:
+        (WTF::HashMap::keys):
+        (WTF::HashMap::values):
+        * wtf/RefPtrHashMap.h:
+        Update for rename to IteratorRange. Simplify by using makeIteratorRange().
+
+        * wtf/IteratorAdaptors.h: Copied from wtf/FilterIterator.h.
+        (WTF::FilterIterator::FilterIterator):
+        (WTF::FilterIterator::operator*):
+        (WTF::makeFilterIterator):
+        (WTF::TransformIterator::TransformIterator):
+        (WTF::TransformIterator::operator++):
+        (WTF::TransformIterator::operator*):
+        (WTF::TransformIterator::operator==):
+        (WTF::TransformIterator::operator!=):
+        (WTF::makeTransformIterator):
+        Split up filtering and transforming. Add makeFilterIterator() and makeTransformIterator()
+        helpers.
+
+        * wtf/IteratorPair.h: Removed.
+        * wtf/IteratorRange.h: Copied from wtf/IteratorPair.h.
+        (WTF::IteratorRange::IteratorRange):
+        (WTF::makeIteratorRange):
+        Renamed to IteratorRange and adds makeIteratorRange() helper.
+
 2014-01-10  David Kilzer  <ddkil...@apple.com>
 
         Clean up architectures in xcconfig files

Modified: trunk/Source/WTF/GNUmakefile.list.am (161769 => 161770)


--- trunk/Source/WTF/GNUmakefile.list.am	2014-01-11 19:16:14 UTC (rev 161769)
+++ trunk/Source/WTF/GNUmakefile.list.am	2014-01-11 19:17:55 UTC (rev 161770)
@@ -53,7 +53,6 @@
     Source/WTF/wtf/FeatureDefines.h \
     Source/WTF/wtf/FilePrintStream.cpp \
     Source/WTF/wtf/FilePrintStream.h \
-    Source/WTF/wtf/FilterIterator.h \
     Source/WTF/wtf/FlipBytes.h \
     Source/WTF/wtf/Forward.h \
     Source/WTF/wtf/FunctionDispatcher.cpp \
@@ -73,7 +72,8 @@
     Source/WTF/wtf/HexNumber.h \
     Source/WTF/wtf/InlineASM.h \
     Source/WTF/wtf/Insertion.h \
-    Source/WTF/wtf/IteratorPair.h \
+    Source/WTF/wtf/IteratorAdaptors.h \
+    Source/WTF/wtf/IteratorRange.h \
     Source/WTF/wtf/ListDump.h \
     Source/WTF/wtf/ListHashSet.h \
     Source/WTF/wtf/Locker.h \

Modified: trunk/Source/WTF/WTF.vcxproj/WTF.vcxproj (161769 => 161770)


--- trunk/Source/WTF/WTF.vcxproj/WTF.vcxproj	2014-01-11 19:16:14 UTC (rev 161769)
+++ trunk/Source/WTF/WTF.vcxproj/WTF.vcxproj	2014-01-11 19:17:55 UTC (rev 161770)
@@ -197,7 +197,6 @@
     <ClInclude Include="..\wtf\FastMalloc.h" />
     <ClInclude Include="..\wtf\FeatureDefines.h" />
     <ClInclude Include="..\wtf\FilePrintStream.h" />
-    <ClInclude Include="..\wtf\FilterIterator.h" />
     <ClInclude Include="..\wtf\FlipBytes.h" />
     <ClInclude Include="..\wtf\Forward.h" />
     <ClInclude Include="..\wtf\FunctionDispatcher.h" />
@@ -217,7 +216,8 @@
     <ClInclude Include="..\wtf\HashTable.h" />
     <ClInclude Include="..\wtf\HashTraits.h" />
     <ClInclude Include="..\wtf\HexNumber.h" />
-    <ClInclude Include="..\wtf\IteratorPair.h" />
+    <ClInclude Include="..\wtf\IteratorAdaptors.h" />
+    <ClInclude Include="..\wtf\IteratorRange.h" />
     <ClInclude Include="..\wtf\ListHashSet.h" />
     <ClInclude Include="..\wtf\Locker.h" />
     <ClInclude Include="..\wtf\MainThread.h" />

Modified: trunk/Source/WTF/WTF.vcxproj/WTF.vcxproj.filters (161769 => 161770)


--- trunk/Source/WTF/WTF.vcxproj/WTF.vcxproj.filters	2014-01-11 19:16:14 UTC (rev 161769)
+++ trunk/Source/WTF/WTF.vcxproj/WTF.vcxproj.filters	2014-01-11 19:17:55 UTC (rev 161770)
@@ -435,9 +435,6 @@
     <ClInclude Include="..\wtf\FilePrintStream.h">
       <Filter>wtf</Filter>
     </ClInclude>
-    <ClInclude Include="..\wtf\FilterIterator.h">
-      <Filter>wtf</Filter>
-    </ClInclude>
     <ClInclude Include="..\wtf\Forward.h">
       <Filter>wtf</Filter>
     </ClInclude>
@@ -474,9 +471,12 @@
     <ClInclude Include="..\wtf\HexNumber.h">
       <Filter>wtf</Filter>
     </ClInclude>
-    <ClInclude Include="..\wtf\IteratorPair.h">
+    <ClInclude Include="..\wtf\IteratorAdaptors.h">
       <Filter>wtf</Filter>
     </ClInclude>
+    <ClInclude Include="..\wtf\IteratorRange.h">
+      <Filter>wtf</Filter>
+    </ClInclude>
     <ClInclude Include="..\wtf\ListHashSet.h">
       <Filter>wtf</Filter>
     </ClInclude>

Modified: trunk/Source/WTF/WTF.xcodeproj/project.pbxproj (161769 => 161770)


--- trunk/Source/WTF/WTF.xcodeproj/project.pbxproj	2014-01-11 19:16:14 UTC (rev 161769)
+++ trunk/Source/WTF/WTF.xcodeproj/project.pbxproj	2014-01-11 19:17:55 UTC (rev 161770)
@@ -65,8 +65,8 @@
 		2CDED0EF18115C38004DBA70 /* RunLoopCF.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 2CDED0EE18115C38004DBA70 /* RunLoopCF.cpp */; };
 		2CDED0F318115C85004DBA70 /* RunLoop.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 2CDED0F118115C85004DBA70 /* RunLoop.cpp */; };
 		2CDED0F418115C85004DBA70 /* RunLoop.h in Headers */ = {isa = PBXBuildFile; fileRef = 2CDED0F218115C85004DBA70 /* RunLoop.h */; };
-		7CDD7FF8186D291E007433CD /* FilterIterator.h in Headers */ = {isa = PBXBuildFile; fileRef = 7CDD7FF7186D291E007433CD /* FilterIterator.h */; };
-		7CDD7FFA186D2A54007433CD /* IteratorPair.h in Headers */ = {isa = PBXBuildFile; fileRef = 7CDD7FF9186D2A54007433CD /* IteratorPair.h */; };
+		7CDD7FF8186D291E007433CD /* IteratorAdaptors.h in Headers */ = {isa = PBXBuildFile; fileRef = 7CDD7FF7186D291E007433CD /* IteratorAdaptors.h */; };
+		7CDD7FFA186D2A54007433CD /* IteratorRange.h in Headers */ = {isa = PBXBuildFile; fileRef = 7CDD7FF9186D2A54007433CD /* IteratorRange.h */; };
 		7E29C33E15FFD79B00516D61 /* ObjcRuntimeExtras.h in Headers */ = {isa = PBXBuildFile; fileRef = 7E29C33D15FFD79B00516D61 /* ObjcRuntimeExtras.h */; };
 		8134013815B092FD001FF0B8 /* Base64.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 8134013615B092FD001FF0B8 /* Base64.cpp */; };
 		8134013915B092FD001FF0B8 /* Base64.h in Headers */ = {isa = PBXBuildFile; fileRef = 8134013715B092FD001FF0B8 /* Base64.h */; };
@@ -339,8 +339,8 @@
 		5D247B7014689C4700E78B76 /* DebugRelease.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = DebugRelease.xcconfig; sourceTree = "<group>"; };
 		5D247B7314689C4700E78B76 /* WTF.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = WTF.xcconfig; sourceTree = "<group>"; };
 		6541CAF41630DB26006D0DEC /* CopyWTFHeaders.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; path = CopyWTFHeaders.xcconfig; sourceTree = "<group>"; };
-		7CDD7FF7186D291E007433CD /* FilterIterator.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FilterIterator.h; sourceTree = "<group>"; };
-		7CDD7FF9186D2A54007433CD /* IteratorPair.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = IteratorPair.h; sourceTree = "<group>"; };
+		7CDD7FF7186D291E007433CD /* IteratorAdaptors.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = IteratorAdaptors.h; sourceTree = "<group>"; };
+		7CDD7FF9186D2A54007433CD /* IteratorRange.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = IteratorRange.h; sourceTree = "<group>"; };
 		7E29C33D15FFD79B00516D61 /* ObjcRuntimeExtras.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ObjcRuntimeExtras.h; sourceTree = "<group>"; };
 		8134013615B092FD001FF0B8 /* Base64.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = Base64.cpp; sourceTree = "<group>"; };
 		8134013715B092FD001FF0B8 /* Base64.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Base64.h; sourceTree = "<group>"; };
@@ -700,8 +700,6 @@
 				A8A472A1151A825A004123FF /* FastMalloc.cpp */,
 				A8A472A2151A825A004123FF /* FastMalloc.h */,
 				B38FD7BC168953E80065C969 /* FeatureDefines.h */,
-				7CDD7FF7186D291E007433CD /* FilterIterator.h */,
-				7CDD7FF9186D2A54007433CD /* IteratorPair.h */,
 				0F9D335B165DBA73005AD387 /* FilePrintStream.cpp */,
 				0F9D335C165DBA73005AD387 /* FilePrintStream.h */,
 				0F2B66A517B6B4F700A7AE3F /* FlipBytes.h */,
@@ -723,6 +721,8 @@
 				A8A472BB151A825A004123FF /* HexNumber.h */,
 				A8A472BC151A825A004123FF /* InlineASM.h */,
 				A70DA0821799F04D00529A9B /* Insertion.h */,
+				7CDD7FF7186D291E007433CD /* IteratorAdaptors.h */,
+				7CDD7FF9186D2A54007433CD /* IteratorRange.h */,
 				A70DA0831799F04D00529A9B /* ListDump.h */,
 				A8A472C1151A825A004123FF /* ListHashSet.h */,
 				A8A472C3151A825A004123FF /* Locker.h */,
@@ -958,7 +958,7 @@
 				A8A47387151A825B004123FF /* Assertions.h in Headers */,
 				A8A47388151A825B004123FF /* Atomics.h in Headers */,
 				A8A47436151A825B004123FF /* AtomicString.h in Headers */,
-				7CDD7FF8186D291E007433CD /* FilterIterator.h in Headers */,
+				7CDD7FF8186D291E007433CD /* IteratorAdaptors.h in Headers */,
 				A8A47437151A825B004123FF /* AtomicStringHash.h in Headers */,
 				A8A47438151A825B004123FF /* AtomicStringImpl.h in Headers */,
 				9BD8F40B176C2B470002D865 /* AtomicStringTable.h in Headers */,
@@ -967,7 +967,7 @@
 				8134013915B092FD001FF0B8 /* Base64.h in Headers */,
 				A8A473A9151A825B004123FF /* bignum-dtoa.h in Headers */,
 				A8A473AB151A825B004123FF /* bignum.h in Headers */,
-				7CDD7FFA186D2A54007433CD /* IteratorPair.h in Headers */,
+				7CDD7FFA186D2A54007433CD /* IteratorRange.h in Headers */,
 				A8A47452151A825B004123FF /* BinarySemaphore.h in Headers */,
 				A8A4738A151A825B004123FF /* Bitmap.h in Headers */,
 				A8A4738C151A825B004123FF /* BitVector.h in Headers */,

Modified: trunk/Source/WTF/wtf/CMakeLists.txt (161769 => 161770)


--- trunk/Source/WTF/wtf/CMakeLists.txt	2014-01-11 19:16:14 UTC (rev 161769)
+++ trunk/Source/WTF/wtf/CMakeLists.txt	2014-01-11 19:17:55 UTC (rev 161770)
@@ -28,7 +28,6 @@
     FastMalloc.h
     FeatureDefines.h
     FilePrintStream.h
-    FilterIterator.h
     FlipBytes.h
     Forward.h
     FunctionDispatcher.h
@@ -43,7 +42,8 @@
     HashTable.h
     HashTraits.h
     HexNumber.h
-    IteratorPair.h
+    IteratorAdaptors.h
+    IteratorRange.h
     ListHashSet.h
     Locker.h
     MD5.h

Deleted: trunk/Source/WTF/wtf/FilterIterator.h (161769 => 161770)


--- trunk/Source/WTF/wtf/FilterIterator.h	2014-01-11 19:16:14 UTC (rev 161769)
+++ trunk/Source/WTF/wtf/FilterIterator.h	2014-01-11 19:17:55 UTC (rev 161770)
@@ -1,77 +0,0 @@
-/*
- * Copyright (C) 2013 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 INC. AND ITS CONTRIBUTORS ``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 INC. OR ITS 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_FilterIterator_h
-#define WTF_FilterIterator_h
-
-#include <wtf/Forward.h>
-#include <wtf/PassRefPtr.h>
-#include <wtf/Vector.h>
-
-namespace WTF {
-
-template<typename Predicate, typename Cast, typename Iterator>
-class FilterIterator {
-public:
-    FilterIterator(Predicate pred, Cast cast, Iterator begin, Iterator end)
-        : m_pred(std::move(pred))
-        , m_cast(std::move(cast))
-        , m_iter(std::move(begin))
-        , m_end(std::move(end))
-    {
-        while (m_iter != m_end && !m_pred(*m_iter))
-            ++m_iter;
-    }
-
-    FilterIterator& operator++()
-    {
-        while (m_iter != m_end) {
-            ++m_iter;
-            if (m_iter == m_end || m_pred(*m_iter))
-                break;
-        }
-        return *this;
-    }
-
-    const decltype(std::declval<Cast>()(*std::declval<Iterator>())) operator*() const
-    {
-        ASSERT(m_iter != m_end);
-        ASSERT(m_pred(*m_iter));
-        return m_cast(*m_iter);
-    }
-
-    inline bool operator==(FilterIterator& other) const { return m_iter == other.m_iter; }
-    inline bool operator!=(FilterIterator& other) const { return m_iter != other.m_iter; }
-
-private:
-    const Predicate m_pred;
-    const Cast m_cast;
-    Iterator m_iter;
-    Iterator m_end;
-};
-
-} // namespace WTF
-
-#endif // WTF_FilterIterator_h

Modified: trunk/Source/WTF/wtf/HashMap.h (161769 => 161770)


--- trunk/Source/WTF/wtf/HashMap.h	2014-01-11 19:16:14 UTC (rev 161769)
+++ trunk/Source/WTF/wtf/HashMap.h	2014-01-11 19:17:55 UTC (rev 161770)
@@ -22,7 +22,7 @@
 #define WTF_HashMap_h
 
 #include <wtf/HashTable.h>
-#include <wtf/IteratorPair.h>
+#include <wtf/IteratorRange.h>
 
 namespace WTF {
 
@@ -92,11 +92,11 @@
     const_iterator begin() const;
     const_iterator end() const;
 
-    IteratorPair<typename iterator::Keys> keys() { return IteratorPair<typename iterator::Keys>(begin().keys(), end().keys()); }
-    const IteratorPair<typename const_iterator::Keys> keys() const { return IteratorPair<typename const_iterator::Keys>(begin().keys(), end().keys()); }
+    IteratorRange<typename iterator::Keys> keys() { return makeIteratorRange(begin().keys(), end().keys()); }
+    const IteratorRange<typename const_iterator::Keys> keys() const { return makeIteratorRange(begin().keys(), end().keys()); }
 
-    IteratorPair<typename iterator::Values> values() { return IteratorPair<typename iterator::Values>(begin().values(), end().values()); }
-    const IteratorPair<typename const_iterator::Values> values() const { return IteratorPair<typename const_iterator::Values>(begin().values(), end().values()); }
+    IteratorRange<typename iterator::Values> values() { return makeIteratorRange(begin().values(), end().values()); }
+    const IteratorRange<typename const_iterator::Values> values() const { return makeIteratorRange(begin().values(), end().values()); }
 
     iterator find(const KeyType&);
     const_iterator find(const KeyType&) const;

Copied: trunk/Source/WTF/wtf/IteratorAdaptors.h (from rev 161750, trunk/Source/WTF/wtf/FilterIterator.h) (0 => 161770)


--- trunk/Source/WTF/wtf/IteratorAdaptors.h	                        (rev 0)
+++ trunk/Source/WTF/wtf/IteratorAdaptors.h	2014-01-11 19:17:55 UTC (rev 161770)
@@ -0,0 +1,111 @@
+/*
+ * Copyright (C) 2013 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 INC. AND ITS CONTRIBUTORS ``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 INC. OR ITS 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_IteratorAdaptors_h
+#define WTF_IteratorAdaptors_h
+
+namespace WTF {
+
+template<typename Predicate, typename Iterator>
+class FilterIterator {
+public:
+    FilterIterator(Predicate pred, Iterator begin, Iterator end)
+        : m_pred(std::move(pred))
+        , m_iter(std::move(begin))
+        , m_end(std::move(end))
+    {
+        while (m_iter != m_end && !m_pred(*m_iter))
+            ++m_iter;
+    }
+
+    FilterIterator& operator++()
+    {
+        while (m_iter != m_end) {
+            ++m_iter;
+            if (m_iter == m_end || m_pred(*m_iter))
+                break;
+        }
+        return *this;
+    }
+
+    const decltype(*std::declval<Iterator>()) operator*() const
+    {
+        ASSERT(m_iter != m_end);
+        ASSERT(m_pred(*m_iter));
+        return *m_iter;
+    }
+
+    inline bool operator==(FilterIterator& other) const { return m_iter == other.m_iter; }
+    inline bool operator!=(FilterIterator& other) const { return m_iter != other.m_iter; }
+
+private:
+    const Predicate m_pred;
+    Iterator m_iter;
+    Iterator m_end;
+};
+
+template<typename Predicate, typename Iterator>
+inline FilterIterator<Predicate, Iterator> makeFilterIterator(Predicate&& pred, Iterator&& begin, Iterator&& end)
+{
+    return FilterIterator<Predicate, Iterator>(std::forward<Predicate>(pred), std::forward<Iterator>(begin), std::forward<Iterator>(end));
+}
+
+template<typename Transform, typename Iterator>
+class TransformIterator {
+public:
+    TransformIterator(const Transform& transform, const Iterator& iter)
+        : m_transform(std::move(transform))
+        , m_iter(std::move(iter))
+    {
+    }
+
+    TransformIterator& operator++()
+    {
+        ++m_iter;
+        return *this;
+    }
+
+    const decltype(std::declval<Transform>()(*std::declval<Iterator>())) operator*() const
+    {
+        return m_transform(*m_iter);
+    }
+
+    inline bool operator==(TransformIterator& other) const { return m_iter == other.m_iter; }
+    inline bool operator!=(TransformIterator& other) const { return m_iter != other.m_iter; }
+
+private:
+    const Transform m_transform;
+    Iterator m_iter;
+};
+
+template<typename Transform, typename Iterator>
+inline TransformIterator<Transform, Iterator> makeTransformIterator(Transform&& transform, Iterator&& iter)
+{
+    return TransformIterator<Transform, Iterator>(std::forward<Transform>(transform), std::forward<Iterator>(iter));
+}
+
+} // namespace WTF
+
+#endif // WTF_IteratorAdaptors_h

Deleted: trunk/Source/WTF/wtf/IteratorPair.h (161769 => 161770)


--- trunk/Source/WTF/wtf/IteratorPair.h	2014-01-11 19:16:14 UTC (rev 161769)
+++ trunk/Source/WTF/wtf/IteratorPair.h	2014-01-11 19:17:55 UTC (rev 161770)
@@ -1,50 +0,0 @@
-/*
- * Copyright (C) 2013 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 INC. AND ITS CONTRIBUTORS ``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 INC. OR ITS 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_IteratorPair_h
-#define WTF_IteratorPair_h
-
-namespace WTF {
-
-template<typename Iterator>
-class IteratorPair {
-public:
-    IteratorPair(Iterator begin, Iterator end)
-        : m_begin(std::move(begin))
-        , m_end(std::move(end))
-    {
-    }
-
-    Iterator begin() const { return m_begin; }
-    Iterator end() const { return m_end; }
-
-private:
-    Iterator m_begin;
-    Iterator m_end;
-};
-
-} // namespace WTF
-
-#endif // WTF_IteratorPair

Copied: trunk/Source/WTF/wtf/IteratorRange.h (from rev 161736, trunk/Source/WTF/wtf/IteratorPair.h) (0 => 161770)


--- trunk/Source/WTF/wtf/IteratorRange.h	                        (rev 0)
+++ trunk/Source/WTF/wtf/IteratorRange.h	2014-01-11 19:17:55 UTC (rev 161770)
@@ -0,0 +1,56 @@
+/*
+ * Copyright (C) 2013 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 INC. AND ITS CONTRIBUTORS ``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 INC. OR ITS 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_IteratorRange_h
+#define WTF_IteratorRange_h
+
+namespace WTF {
+
+template<typename Iterator>
+class IteratorRange {
+public:
+    IteratorRange(Iterator begin, Iterator end)
+        : m_begin(std::move(begin))
+        , m_end(std::move(end))
+    {
+    }
+
+    Iterator begin() const { return m_begin; }
+    Iterator end() const { return m_end; }
+
+private:
+    Iterator m_begin;
+    Iterator m_end;
+};
+
+template<typename Iterator>
+IteratorRange<Iterator> makeIteratorRange(Iterator&& begin, Iterator&& end)
+{
+    return IteratorRange<Iterator>(std::forward<Iterator>(begin), std::forward<Iterator>(end));
+}
+
+} // namespace WTF
+
+#endif // WTF_IteratorRange_h

Modified: trunk/Source/WTF/wtf/RefPtrHashMap.h (161769 => 161770)


--- trunk/Source/WTF/wtf/RefPtrHashMap.h	2014-01-11 19:16:14 UTC (rev 161769)
+++ trunk/Source/WTF/wtf/RefPtrHashMap.h	2014-01-11 19:17:55 UTC (rev 161770)
@@ -70,11 +70,11 @@
         const_iterator begin() const;
         const_iterator end() const;
 
-        IteratorPair<typename iterator::Keys> keys() { return IteratorPair<typename iterator::Keys>(begin().keys(), end().keys()); }
-        const IteratorPair<typename const_iterator::Keys> keys() const { return IteratorPair<typename const_iterator::Keys>(begin().keys(), end().keys()); }
+        IteratorRange<typename iterator::Keys> keys() { return makeIteratorRange(begin().keys(), end().keys()); }
+        const IteratorRange<typename const_iterator::Keys> keys() const { return makeIteratorRange(begin().keys(), end().keys()); }
 
-        IteratorPair<typename iterator::Values> values() { return IteratorPair<typename iterator::Values>(begin().values(), end().values()); }
-        const IteratorPair<typename const_iterator::Values> values() const { return IteratorPair<typename const_iterator::Values>(begin().values(), end().values()); }
+        IteratorRange<typename iterator::Values> values() { return makeIteratorRange(begin().values(), end().values()); }
+        const IteratorRange<typename const_iterator::Values> values() const { return makeIteratorRange(begin().values(), end().values()); }
 
         iterator find(const KeyType&);
         iterator find(RawKeyType);

Modified: trunk/Source/WebKit2/ChangeLog (161769 => 161770)


--- trunk/Source/WebKit2/ChangeLog	2014-01-11 19:16:14 UTC (rev 161769)
+++ trunk/Source/WebKit2/ChangeLog	2014-01-11 19:17:55 UTC (rev 161770)
@@ -1,3 +1,15 @@
+2014-01-11  Sam Weinig  <s...@webkit.org>
+
+        Clean up iterator filter / iterator range code
+        https://bugs.webkit.org/show_bug.cgi?id=126817
+
+        Reviewed by Anders Carlsson.
+
+        * Shared/APIArray.h:
+        Update elementsOfType() to use combination of FilterIterator and TransformIterator
+        (now that FilterIterator no longer has a transform predicate) and make use of the 
+        makeFoo() helpers.
+
 2014-01-11  Anders Carlsson  <ander...@apple.com>
 
         Simplify Timer and DeferrableOneShotTimer using std::function

Modified: trunk/Source/WebKit2/Shared/APIArray.h (161769 => 161770)


--- trunk/Source/WebKit2/Shared/APIArray.h	2014-01-11 19:16:14 UTC (rev 161769)
+++ trunk/Source/WebKit2/Shared/APIArray.h	2014-01-11 19:17:55 UTC (rev 161770)
@@ -27,9 +27,9 @@
 #define APIArray_h
 
 #include "APIObject.h"
-#include <wtf/FilterIterator.h>
 #include <wtf/Forward.h>
-#include <wtf/IteratorPair.h>
+#include <wtf/IteratorAdaptors.h>
+#include <wtf/IteratorRange.h>
 #include <wtf/PassRefPtr.h>
 #include <wtf/Vector.h>
 
@@ -37,12 +37,19 @@
 
 class Array FINAL : public ObjectImpl<Object::Type::Array> {
 private:
-    template<typename T>
-    static inline const T* getObject(const RefPtr<Object>& object) { return static_cast<const T*>(object.get()); }
+    template <class T>
+    struct IsTypePredicate {
+        bool operator()(const RefPtr<Object>& object) const { return object->type() == T::APIType; }
+    };
 
-    template<typename T>
-    static inline bool isType(const RefPtr<Object>& object) { return object->type() == T::APIType; }
+    template <class T>
+    struct GetObjectTransform {
+        const T* operator()(const RefPtr<Object>& object) const { return static_cast<const T*>(object.get()); }
+    };
 
+    template <typename T>
+    using ElementsOfTypeRange = WTF::IteratorRange<WTF::TransformIterator<GetObjectTransform<T>, WTF::FilterIterator<IsTypePredicate<T>, Vector<RefPtr<Object>>::const_iterator>>>;
+
 public:
     static PassRefPtr<Array> create();
     static PassRefPtr<Array> create(Vector<RefPtr<Object>> elements);
@@ -53,7 +60,7 @@
     template<typename T>
     T* at(size_t i) const
     {
-        if (!isType<T>(m_elements[i]))
+        if (m_elements[i]->type() != T::APIType)
             return nullptr;
 
         return static_cast<T*>(m_elements[i].get());
@@ -66,13 +73,11 @@
     Vector<RefPtr<Object>>& elements() { return m_elements; }
 
     template<typename T>
-    WTF::IteratorPair<WTF::FilterIterator<decltype(&isType<T>), decltype(&getObject<T>), Vector<RefPtr<Object>>::const_iterator>> elementsOfType()
+    ElementsOfTypeRange<T> elementsOfType() const
     {
-        typedef WTF::FilterIterator<decltype(&isType<T>), decltype(&getObject<T>), Vector<RefPtr<Object>>::const_iterator> Iterator;
-    
-        return WTF::IteratorPair<Iterator>(
-            Iterator(isType<T>, getObject<T>, m_elements.begin(), m_elements.end()),
-            Iterator(isType<T>, getObject<T>, m_elements.end(), m_elements.end())
+        return WTF::makeIteratorRange(
+            WTF::makeTransformIterator(GetObjectTransform<T>(), WTF::makeFilterIterator(IsTypePredicate<T>(), m_elements.begin(), m_elements.end())),
+            WTF::makeTransformIterator(GetObjectTransform<T>(), WTF::makeFilterIterator(IsTypePredicate<T>(), m_elements.end(), m_elements.end()))
         );
     }
 
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to