From 8bf3a0a368ee4aa7cd58cf9259fc7d8acae3cad2 Mon Sep 17 00:00:00 2001 From: Ivailo Monev Date: Thu, 1 Aug 2019 11:26:50 +0000 Subject: [PATCH] use memcpy() for buffers copy in JavaScriptCore where possible Signed-off-by: Ivailo Monev --- src/3rdparty/javascriptcore/runtime/UString.cpp | 4 ++-- src/3rdparty/javascriptcore/runtime/UString.h | 9 +++------ 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/src/3rdparty/javascriptcore/runtime/UString.cpp b/src/3rdparty/javascriptcore/runtime/UString.cpp index d6ff802bf..d6818cbe5 100644 --- a/src/3rdparty/javascriptcore/runtime/UString.cpp +++ b/src/3rdparty/javascriptcore/runtime/UString.cpp @@ -374,8 +374,8 @@ UString& UString::operator=(const char* c) UChar* d = 0; m_rep = Rep::tryCreateUninitialized(l, d); if (m_rep) { - for (int i = 0; i < l; i++) - d[i] = static_cast(c[i]); // use unsigned char to zero-extend instead of sign-extend + // use unsigned char to zero-extend instead of sign-extend + memcpy(d, reinterpret_cast(c), l * sizeof(unsigned char)); } else makeNull(); diff --git a/src/3rdparty/javascriptcore/runtime/UString.h b/src/3rdparty/javascriptcore/runtime/UString.h index 777f411da..270c052f3 100644 --- a/src/3rdparty/javascriptcore/runtime/UString.h +++ b/src/3rdparty/javascriptcore/runtime/UString.h @@ -273,8 +273,7 @@ namespace JSC { void writeTo(UChar* destination) { - for (unsigned i = 0; i < m_length; ++i) - destination[i] = m_buffer[i]; + memcpy(destination, reinterpret_cast(m_buffer), m_length * sizeof(UChar)); } private: @@ -295,8 +294,7 @@ namespace JSC { void writeTo(UChar* destination) { - for (unsigned i = 0; i < m_length; ++i) - destination[i] = m_buffer[i]; + memcpy(destination, reinterpret_cast(m_buffer), m_length * sizeof(UChar)); } private: @@ -317,8 +315,7 @@ namespace JSC { void writeTo(UChar* destination) { - for (unsigned i = 0; i < m_length; ++i) - destination[i] = m_data[i]; + memcpy(destination, m_data, m_length * sizeof(UChar)); } private: -- 2.11.0