Commit 7259d87f authored by yangguo@chromium.org's avatar yangguo@chromium.org

Use memcpy in List::AddAll for fundamental types.

R=svenpanne@chromium.org

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

Cr-Commit-Position: refs/heads/master@{#24868}
git-svn-id: https://v8.googlecode.com/svn/branches/bleeding_edge@24868 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent 119bbee8
......@@ -398,4 +398,22 @@ inline T RoundUp(T x, intptr_t m) {
return RoundDown<T>(static_cast<T>(x + m - 1), m);
}
namespace v8 {
namespace base {
// TODO(yangguo): This is a poor man's replacement for std::is_fundamental,
// which requires C++11. Switch to std::is_fundamental once possible.
template <typename T>
inline bool is_fundamental() {
return false;
}
template <>
inline bool is_fundamental<uint8_t>() {
return true;
}
}
} // namespace v8::base
#endif // V8_BASE_MACROS_H_
......@@ -7,6 +7,7 @@
#include "src/list.h"
#include "src/base/macros.h"
#include "src/base/platform/platform.h"
namespace v8 {
......@@ -33,8 +34,10 @@ template<typename T, class P>
void List<T, P>::AddAll(const Vector<T>& other, P alloc) {
int result_length = length_ + other.length();
if (capacity_ < result_length) Resize(result_length, alloc);
for (int i = 0; i < other.length(); i++) {
data_[length_ + i] = other.at(i);
if (base::is_fundamental<T>()) {
memcpy(data_ + length_, other.start(), sizeof(*data_) * other.length());
} else {
for (int i = 0; i < other.length(); i++) data_[length_ + i] = other.at(i);
}
length_ = result_length;
}
......
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