Revision: 24868
Author:   [email protected]
Date:     Fri Oct 24 12:33:58 2014 UTC
Log:      Use memcpy in List::AddAll for fundamental types.

[email protected]

Review URL: https://codereview.chromium.org/663893004
https://code.google.com/p/v8/source/detail?r=24868

Modified:
 /branches/bleeding_edge/src/base/macros.h
 /branches/bleeding_edge/src/list-inl.h

=======================================
--- /branches/bleeding_edge/src/base/macros.h   Tue Oct 21 08:25:14 2014 UTC
+++ /branches/bleeding_edge/src/base/macros.h   Fri Oct 24 12:33:58 2014 UTC
@@ -397,5 +397,23 @@
 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_
=======================================
--- /branches/bleeding_edge/src/list-inl.h      Mon Aug  4 11:34:54 2014 UTC
+++ /branches/bleeding_edge/src/list-inl.h      Fri Oct 24 12:33:58 2014 UTC
@@ -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 @@
 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;
 }

--
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
--- You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to