Title: [102483] trunk
Revision
102483
Author
[email protected]
Date
2011-12-09 15:43:52 -0800 (Fri, 09 Dec 2011)

Log Message

Hash* iterators should allow comparison between const and const versions.
https://bugs.webkit.org/show_bug.cgi?id=73370

Reviewed by Darin Adler.

Source/_javascript_Core:

* wtf/HashTable.h: Add the operators needed to do this.
(WTF::HashTableConstIterator::operator==):
(WTF::HashTableConstIterator::operator!=):
(WTF::HashTableIterator::operator==):
(WTF::HashTableIterator::operator!=):
(WTF::operator==):
(WTF::operator!=):

Tools:

* TestWebKitAPI/TestWebKitAPI.gypi: Add the new test file to the build.
* TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj: Ditto.
* TestWebKitAPI/win/TestWebKitAPI.vcproj: Ditto.
* TestWebKitAPI/Tests/WTF/HashMap.cpp: Added.
(TestWebKitAPI::TEST): Add a test for the new functionality.

Modified Paths

Added Paths

Diff

Modified: trunk/Source/_javascript_Core/ChangeLog (102482 => 102483)


--- trunk/Source/_javascript_Core/ChangeLog	2011-12-09 23:39:45 UTC (rev 102482)
+++ trunk/Source/_javascript_Core/ChangeLog	2011-12-09 23:43:52 UTC (rev 102483)
@@ -1,3 +1,18 @@
+2011-12-09  David Levin  <[email protected]>
+
+        Hash* iterators should allow comparison between const and const versions.
+        https://bugs.webkit.org/show_bug.cgi?id=73370
+
+        Reviewed by Darin Adler.
+
+        * wtf/HashTable.h: Add the operators needed to do this.
+        (WTF::HashTableConstIterator::operator==):
+        (WTF::HashTableConstIterator::operator!=):
+        (WTF::HashTableIterator::operator==):
+        (WTF::HashTableIterator::operator!=):
+        (WTF::operator==):
+        (WTF::operator!=):
+
 2011-12-09  Michael Saboff  <[email protected]>
 
         YARR: Multi-character read optimization for 8bit strings

Modified: trunk/Source/_javascript_Core/wtf/HashTable.h (102482 => 102483)


--- trunk/Source/_javascript_Core/wtf/HashTable.h	2011-12-09 23:39:45 UTC (rev 102482)
+++ trunk/Source/_javascript_Core/wtf/HashTable.h	2011-12-09 23:43:52 UTC (rev 102483)
@@ -188,6 +188,14 @@
             checkValidity(other);
             return m_position != other.m_position;
         }
+        bool operator==(const iterator& other) const
+        {
+            return *this == static_cast<const_iterator>(other);
+        }
+        bool operator!=(const iterator& other) const
+        {
+            return *this != static_cast<const_iterator>(other);
+        }
 
     private:
         void checkValidity() const
@@ -253,6 +261,8 @@
         // Comparison.
         bool operator==(const iterator& other) const { return m_iterator == other.m_iterator; }
         bool operator!=(const iterator& other) const { return m_iterator != other.m_iterator; }
+        bool operator==(const const_iterator& other) const { return m_iterator == other; }
+        bool operator!=(const const_iterator& other) const { return m_iterator != other; }
 
         operator const_iterator() const { return m_iterator; }
 
@@ -1202,6 +1212,31 @@
         return a.m_impl != b.m_impl;
     }
 
+    // All 4 combinations of ==, != and Const,non const.
+    template<typename T, typename U>
+    inline bool operator==(const HashTableConstIteratorAdapter<T, U>& a, const HashTableIteratorAdapter<T, U>& b)
+    {
+        return a.m_impl == b.m_impl;
+    }
+
+    template<typename T, typename U>
+    inline bool operator!=(const HashTableConstIteratorAdapter<T, U>& a, const HashTableIteratorAdapter<T, U>& b)
+    {
+        return a.m_impl != b.m_impl;
+    }
+
+    template<typename T, typename U>
+    inline bool operator==(const HashTableIteratorAdapter<T, U>& a, const HashTableConstIteratorAdapter<T, U>& b)
+    {
+        return a.m_impl == b.m_impl;
+    }
+
+    template<typename T, typename U>
+    inline bool operator!=(const HashTableIteratorAdapter<T, U>& a, const HashTableConstIteratorAdapter<T, U>& b)
+    {
+        return a.m_impl != b.m_impl;
+    }
+
 } // namespace WTF
 
 #include "HashIterators.h"

Modified: trunk/Tools/ChangeLog (102482 => 102483)


--- trunk/Tools/ChangeLog	2011-12-09 23:39:45 UTC (rev 102482)
+++ trunk/Tools/ChangeLog	2011-12-09 23:43:52 UTC (rev 102483)
@@ -1,3 +1,16 @@
+2011-12-09  David Levin  <[email protected]>
+
+        Hash* iterators should allow comparison between const and const versions.
+        https://bugs.webkit.org/show_bug.cgi?id=73370
+
+        Reviewed by Darin Adler.
+
+        * TestWebKitAPI/TestWebKitAPI.gypi: Add the new test file to the build.
+        * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj: Ditto.
+        * TestWebKitAPI/win/TestWebKitAPI.vcproj: Ditto.
+        * TestWebKitAPI/Tests/WTF/HashMap.cpp: Added.
+        (TestWebKitAPI::TEST): Add a test for the new functionality.
+
 2011-12-09  Dirk Pranke  <[email protected]>
 
         chromium: visual studio projects are busted when build_webkit_exes_from_webkit_gyp==0

Modified: trunk/Tools/TestWebKitAPI/TestWebKitAPI.gypi (102482 => 102483)


--- trunk/Tools/TestWebKitAPI/TestWebKitAPI.gypi	2011-12-09 23:39:45 UTC (rev 102482)
+++ trunk/Tools/TestWebKitAPI/TestWebKitAPI.gypi	2011-12-09 23:43:52 UTC (rev 102483)
@@ -32,6 +32,7 @@
     'variables': {
         'TestWebKitAPI_files': [
             'Tests/WTF/CheckedArithmeticOperations.cpp',
+            'Tests/WTF/HashMap.cpp',
             'Tests/WTF/RedBlackTree.cpp',
             'Tests/WTF/StringBuilder.cpp',
             'Tests/WTF/StringOperators.cpp',

Modified: trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj (102482 => 102483)


--- trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj	2011-12-09 23:39:45 UTC (rev 102482)
+++ trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj	2011-12-09 23:43:52 UTC (rev 102483)
@@ -9,6 +9,7 @@
 /* Begin PBXBuildFile section */
 		0BCD856A1485C98B00EA2003 /* TemporaryChange.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 0BCD85691485C98B00EA2003 /* TemporaryChange.cpp */; };
 		0FC6C4CC141027E0005B7F0C /* RedBlackTree.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 0FC6C4CB141027E0005B7F0C /* RedBlackTree.cpp */; };
+		0BCD833514857CE400EA2003 /* HashMap.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 0BCD833414857CE400EA2003 /* HashMap.cpp */; };
 		0FC6C4CF141034AD005B7F0C /* MetaAllocator.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 0FC6C4CE141034AD005B7F0C /* MetaAllocator.cpp */; };
 		1A02C84F125D4A8400E3F4BD /* Find.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1A02C84E125D4A8400E3F4BD /* Find.cpp */; };
 		1A02C870125D4CFD00E3F4BD /* find.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 1A02C84B125D4A5E00E3F4BD /* find.html */; };
@@ -151,6 +152,7 @@
 /* Begin PBXFileReference section */
 		0BCD85691485C98B00EA2003 /* TemporaryChange.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = TemporaryChange.cpp; path = WTF/TemporaryChange.cpp; sourceTree = "<group>"; };
 		0FC6C4CB141027E0005B7F0C /* RedBlackTree.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = RedBlackTree.cpp; path = WTF/RedBlackTree.cpp; sourceTree = "<group>"; };
+		0BCD833414857CE400EA2003 /* HashMap.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = HashMap.cpp; path = WTF/HashMap.cpp; sourceTree = "<group>"; };
 		0FC6C4CE141034AD005B7F0C /* MetaAllocator.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = MetaAllocator.cpp; path = WTF/MetaAllocator.cpp; sourceTree = "<group>"; };
 		1A02C84B125D4A5E00E3F4BD /* find.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = find.html; sourceTree = "<group>"; };
 		1A02C84E125D4A8400E3F4BD /* Find.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = Find.cpp; sourceTree = "<group>"; };
@@ -431,6 +433,7 @@
 				0FC6C4CE141034AD005B7F0C /* MetaAllocator.cpp */,
 				0FC6C4CB141027E0005B7F0C /* RedBlackTree.cpp */,
 				A7A966DA140ECCC8005EF9B4 /* CheckedArithmeticOperations.cpp */,
+				0BCD833414857CE400EA2003 /* HashMap.cpp */,
 				81B50192140F232300D9EB58 /* StringBuilder.cpp */,
 				C01363C713C3997300EF3964 /* StringOperators.cpp */,
 				0BCD85691485C98B00EA2003 /* TemporaryChange.cpp */,
@@ -679,6 +682,7 @@
 				BC3C4C7214575B6A0025FB62 /* WKBrowsingContextLoadDelegateTest.mm in Sources */,
 				BC3C4C7F14587AA60025FB62 /* WKBrowsingContextGroupTest.mm in Sources */,
 				C0C5D3BE14598B6F00A802A6 /* GetBackingScaleFactor.mm in Sources */,
+				0BCD833514857CE400EA2003 /* HashMap.cpp in Sources */,
 				3722C8691461E03E00C45D00 /* RenderedImageFromDOMRange.mm in Sources */,
 				0BCD856A1485C98B00EA2003 /* TemporaryChange.cpp in Sources */,
 				37A6895F148A9B50005100FA /* SubresourceErrorCrash.mm in Sources */,

Added: trunk/Tools/TestWebKitAPI/Tests/WTF/HashMap.cpp (0 => 102483)


--- trunk/Tools/TestWebKitAPI/Tests/WTF/HashMap.cpp	                        (rev 0)
+++ trunk/Tools/TestWebKitAPI/Tests/WTF/HashMap.cpp	2011-12-09 23:43:52 UTC (rev 102483)
@@ -0,0 +1,52 @@
+/*
+ * Copyright (C) 2011 Google 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.
+ */
+
+#include "config.h"
+
+#include <wtf/HashMap.h>
+
+namespace TestWebKitAPI {
+
+typedef WTF::HashMap<int, int> IntHashMap;
+
+TEST(WTF, HashTableIteratorComparison)
+{
+    IntHashMap map;
+    map.add(1, 2);
+    ASSERT_TRUE(map.begin() != map.end());
+    ASSERT_FALSE(map.begin() == map.end());
+
+    IntHashMap::const_iterator begin = map.begin();
+    ASSERT_TRUE(begin == map.begin());
+    ASSERT_TRUE(map.begin() == begin);
+    ASSERT_TRUE(begin != map.end());
+    ASSERT_TRUE(map.end() != begin);
+    ASSERT_FALSE(begin != map.begin());
+    ASSERT_FALSE(map.begin() != begin);
+    ASSERT_FALSE(begin == map.end());
+    ASSERT_FALSE(map.end() == begin);
+}
+
+} // namespace TestWebKitAPI
Property changes on: trunk/Tools/TestWebKitAPI/Tests/WTF/HashMap.cpp
___________________________________________________________________

Added: svn:eol-style

Modified: trunk/Tools/TestWebKitAPI/win/TestWebKitAPI.vcproj (102482 => 102483)


--- trunk/Tools/TestWebKitAPI/win/TestWebKitAPI.vcproj	2011-12-09 23:39:45 UTC (rev 102482)
+++ trunk/Tools/TestWebKitAPI/win/TestWebKitAPI.vcproj	2011-12-09 23:43:52 UTC (rev 102483)
@@ -640,6 +640,10 @@
 					>
 				</File>
 				<File
+					RelativePath="..\Tests\WTF\HashMap.cpp"
+					>
+				</File>
+				<File
 					RelativePath="..\Tests\WTF\StringOperators.cpp"
 					>
 				</File>
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to