Copy strings 1 word at a time when flattening etc.
authorerik.corry@gmail.com <erik.corry@gmail.com@ce2b1a6d-e550-0410-aec6-3dcde31c8c00>
Thu, 23 Oct 2008 07:20:28 +0000 (07:20 +0000)
committererik.corry@gmail.com <erik.corry@gmail.com@ce2b1a6d-e550-0410-aec6-3dcde31c8c00>
Thu, 23 Oct 2008 07:20:28 +0000 (07:20 +0000)
Review URL: http://codereview.chromium.org/7885

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@562 ce2b1a6d-e550-0410-aec6-3dcde31c8c00

src/utils.h

index 78bb2300238a4c77c392972f22e2076af0674c33..9f2407973d728e8495ea69a915d3a838e8442603 100644 (file)
@@ -447,7 +447,20 @@ class StringBuilder {
 // Copy from ASCII/16bit chars to ASCII/16bit chars.
 template <typename sourcechar, typename sinkchar>
 static inline void CopyChars(sinkchar* dest, const sourcechar* src, int chars) {
-  while (chars--) {
+  sinkchar* limit = dest + chars;
+#ifdef CAN_READ_UNALIGNED
+  if (sizeof(*dest) == sizeof(*src)) {
+    // Number of characters in a uint32_t.
+    static const int kStepSize = sizeof(uint32_t) / sizeof(*dest);  // NOLINT
+    while (dest <= limit - kStepSize) {
+      *reinterpret_cast<uint32_t*>(dest) =
+          *reinterpret_cast<const uint32_t*>(src);
+      dest += kStepSize;
+      src += kStepSize;
+    }
+  }
+#endif
+  while (dest < limit) {
     *dest++ = static_cast<sinkchar>(*src++);
   }
 }