Source/JavaScriptCore: Add Vector::reverse()
authormitz@apple.com <mitz@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 9 Jun 2011 20:29:02 +0000 (20:29 +0000)
committermitz@apple.com <mitz@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 9 Jun 2011 20:29:02 +0000 (20:29 +0000)
https://bugs.webkit.org/show_bug.cgi?id=62393

Reviewed by Anders Carlsson.

* wtf/Vector.h:
(WTF::Vector::reverse): Added

Tools: Added a test for Vector::reverse()
https://bugs.webkit.org/show_bug.cgi?id=62393

Reviewed by Anders Carlsson.

* TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
* TestWebKitAPI/Tests/WTF/VectorReverse.cpp: Added.
(TestWebKitAPI::TEST):
* TestWebKitAPI/win/TestWebKitAPI.vcproj:

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

Source/JavaScriptCore/ChangeLog
Source/JavaScriptCore/wtf/Vector.h
Tools/ChangeLog
Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj
Tools/TestWebKitAPI/Tests/WTF/VectorReverse.cpp [new file with mode: 0644]
Tools/TestWebKitAPI/win/TestWebKitAPI.vcproj

index 8ca1f9f..fc03b81 100644 (file)
@@ -1,3 +1,13 @@
+2011-06-09  Dan Bernstein  <mitz@apple.com>
+
+        Reviewed by Anders Carlsson.
+
+        Add Vector::reverse()
+        https://bugs.webkit.org/show_bug.cgi?id=62393
+
+        * wtf/Vector.h:
+        (WTF::Vector::reverse): Added
+
 2011-06-08  Geoffrey Garen  <ggaren@apple.com>
 
         Reviewed by Oliver Hunt.
index 03c03d5..d5805cc 100644 (file)
@@ -619,6 +619,8 @@ namespace WTF {
             m_buffer.swap(other.m_buffer);
         }
 
+        void reverse();
+
         void checkConsistency();
 
     private:
@@ -1097,6 +1099,13 @@ namespace WTF {
     }
 
     template<typename T, size_t inlineCapacity>
+    inline void Vector<T, inlineCapacity>::reverse()
+    {
+        for (size_t i = 0; i < m_size / 2; ++i)
+            std::swap(at(i), at(m_size - 1 - i));
+    }
+
+    template<typename T, size_t inlineCapacity>
     inline T* Vector<T, inlineCapacity>::releaseBuffer()
     {
         T* buffer = m_buffer.releaseBuffer();
index 6d03551..d0b1081 100644 (file)
@@ -1,3 +1,15 @@
+2011-06-09  Dan Bernstein  <mitz@apple.com>
+
+        Reviewed by Anders Carlsson.
+
+        Added a test for Vector::reverse()
+        https://bugs.webkit.org/show_bug.cgi?id=62393
+
+        * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
+        * TestWebKitAPI/Tests/WTF/VectorReverse.cpp: Added.
+        (TestWebKitAPI::TEST):
+        * TestWebKitAPI/win/TestWebKitAPI.vcproj:
+
 2011-06-09  Martin Robinson  <mrobinson@igalia.com>
 
         Reviewed by Andreas Kling.
index c2963fc..42472c2 100644 (file)
@@ -16,6 +16,7 @@
                33BE5AF5137B5A6C00705813 /* MouseMoveAfterCrash.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 33BE5AF4137B5A6C00705813 /* MouseMoveAfterCrash.cpp */; };
                33BE5AF9137B5AAE00705813 /* MouseMoveAfterCrash_Bundle.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 33BE5AF8137B5AAE00705813 /* MouseMoveAfterCrash_Bundle.cpp */; };
                33E79E06137B5FD900E32D99 /* mouse-move-listener.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 33E79E05137B5FCE00E32D99 /* mouse-move-listener.html */; };
+               37200B9213A16230007A4FAD /* VectorReverse.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 37200B9113A16230007A4FAD /* VectorReverse.cpp */; };
                4BFDFFA71314776C0061F24B /* HitTestResultNodeHandle_Bundle.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4BFDFFA61314776C0061F24B /* HitTestResultNodeHandle_Bundle.cpp */; };
                4BFDFFA9131477770061F24B /* HitTestResultNodeHandle.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4BFDFFA8131477770061F24B /* HitTestResultNodeHandle.cpp */; };
                BC131885117114B600B69727 /* PlatformUtilitiesMac.mm in Sources */ = {isa = PBXBuildFile; fileRef = BC131884117114B600B69727 /* PlatformUtilitiesMac.mm */; };
                33BE5AF4137B5A6C00705813 /* MouseMoveAfterCrash.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = MouseMoveAfterCrash.cpp; sourceTree = "<group>"; };
                33BE5AF8137B5AAE00705813 /* MouseMoveAfterCrash_Bundle.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = MouseMoveAfterCrash_Bundle.cpp; sourceTree = "<group>"; };
                33E79E05137B5FCE00E32D99 /* mouse-move-listener.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = "mouse-move-listener.html"; sourceTree = "<group>"; };
+               37200B9113A16230007A4FAD /* VectorReverse.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = VectorReverse.cpp; path = WTF/VectorReverse.cpp; sourceTree = "<group>"; };
                4BFDFFA61314776C0061F24B /* HitTestResultNodeHandle_Bundle.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = HitTestResultNodeHandle_Bundle.cpp; sourceTree = "<group>"; };
                4BFDFFA8131477770061F24B /* HitTestResultNodeHandle.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = HitTestResultNodeHandle.cpp; sourceTree = "<group>"; };
                8DD76FA10486AA7600D96B5E /* TestWebKitAPI */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = TestWebKitAPI; sourceTree = BUILT_PRODUCTS_DIR; };
                        isa = PBXGroup;
                        children = (
                                BC90964B125561BF00083756 /* VectorBasic.cpp */,
+                               37200B9113A16230007A4FAD /* VectorReverse.cpp */,
                        );
                        name = WTF;
                        sourceTree = "<group>";
                                F6F3F29113342FEB00A6BF19 /* CookieManager.cpp in Sources */,
                                33BE5AF5137B5A6C00705813 /* MouseMoveAfterCrash.cpp in Sources */,
                                C045F9451385C2EA00C0F3CD /* DownloadDecideDestinationCrash.cpp in Sources */,
+                               37200B9213A16230007A4FAD /* VectorReverse.cpp in Sources */,
                        );
                        runOnlyForDeploymentPostprocessing = 0;
                };
diff --git a/Tools/TestWebKitAPI/Tests/WTF/VectorReverse.cpp b/Tools/TestWebKitAPI/Tests/WTF/VectorReverse.cpp
new file mode 100644 (file)
index 0000000..3aeb966
--- /dev/null
@@ -0,0 +1,56 @@
+/*
+ * Copyright (C) 2011 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.
+ */
+
+#include "Test.h"
+
+#include <JavaScriptCore/Vector.h>
+
+namespace TestWebKitAPI {
+
+TEST(WTF, VectorReverse)
+{
+    Vector<int> intVector;
+    intVector.append(10);
+    intVector.append(11);
+    intVector.append(12);
+    intVector.append(13);
+    intVector.reverse();
+
+    EXPECT_EQ(13, intVector[0]);
+    EXPECT_EQ(12, intVector[1]);
+    EXPECT_EQ(11, intVector[2]);
+    EXPECT_EQ(10, intVector[3]);
+
+    intVector.append(9);
+    intVector.reverse();
+
+    EXPECT_EQ(9, intVector[0]);
+    EXPECT_EQ(10, intVector[1]);
+    EXPECT_EQ(11, intVector[2]);
+    EXPECT_EQ(12, intVector[3]);
+    EXPECT_EQ(13, intVector[4]);
+}
+
+} // namespace TestWebKitAPI
index 01a8f8c..2089b59 100644 (file)
                                        RelativePath="..\Tests\WTF\VectorBasic.cpp"
                                        >
                                </File>
+                               <File
+                                       RelativePath="..\Tests\WTF\VectorReverse.cpp"
+                                       >
+                               </File>
                        </Filter>
                </Filter>
                <File