Commit 063b2a76 authored by yoichio@chromium.org's avatar yoichio@chromium.org

VectorComparer should check null.

We use VectorComparer to compare WTF::Vector<T>.
If T is not primitive type, we use std::equal to compare.
By the way, we use the WTF::VectorBufferBase class for a base class of Vector.  VectorBufferBase doesn't alloc a array if we init it without a size argument.
As a conclusion, we pass NULL object to std::equal when we compare Vectors with the default constructor.
It is asserted especially on a Windows debug build.

BUG=

Review URL: https://codereview.chromium.org/332113002

git-svn-id: svn://svn.chromium.org/blink/trunk@176189 bbb929c8-8fbe-4397-9dbb-9b2b20218538
parent 1b172db1
...@@ -224,7 +224,9 @@ static const size_t kInitialVectorSize = WTF_VECTOR_INITIAL_SIZE; ...@@ -224,7 +224,9 @@ static const size_t kInitialVectorSize = WTF_VECTOR_INITIAL_SIZE;
{ {
static bool compare(const T* a, const T* b, size_t size) static bool compare(const T* a, const T* b, size_t size)
{ {
return std::equal(a, a + size, b); if (LIKELY(a && b))
return std::equal(a, a + size, b);
return !a && !b;
} }
}; };
......
...@@ -28,6 +28,7 @@ ...@@ -28,6 +28,7 @@
#include "wtf/HashSet.h" #include "wtf/HashSet.h"
#include "wtf/OwnPtr.h" #include "wtf/OwnPtr.h"
#include "wtf/PassOwnPtr.h" #include "wtf/PassOwnPtr.h"
#include "wtf/text/WTFString.h"
#include "wtf/Vector.h" #include "wtf/Vector.h"
#include <gtest/gtest.h> #include <gtest/gtest.h>
...@@ -283,4 +284,22 @@ TEST(VectorTest, SwapWithInlineCapacity) ...@@ -283,4 +284,22 @@ TEST(VectorTest, SwapWithInlineCapacity)
vectorB.swap(vectorA); vectorB.swap(vectorA);
} }
class Comparable {
};
bool operator==(const Comparable& a, const Comparable& b) { return true; }
template<typename T> void compare()
{
EXPECT_TRUE(Vector<T>() == Vector<T>());
EXPECT_FALSE(Vector<T>(1) == Vector<T>(0));
EXPECT_FALSE(Vector<T>() == Vector<T>(1));
EXPECT_TRUE(Vector<T>(1) == Vector<T>(1));
}
TEST(VectorTest, Compare)
{
compare<int>();
compare<Comparable>();
compare<WTF::String>();
}
} // namespace } // namespace
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment