From f1a9262ae2b1c25a6838fe03bfbec595cc85592b Mon Sep 17 00:00:00 2001 From: Ivailo Monev Date: Wed, 31 Jul 2019 19:15:59 +0000 Subject: [PATCH] use loop instead of while iterator in UString::ascii() Signed-off-by: Ivailo Monev --- src/3rdparty/javascriptcore/runtime/UString.cpp | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/src/3rdparty/javascriptcore/runtime/UString.cpp b/src/3rdparty/javascriptcore/runtime/UString.cpp index 74664e322..d6ff802bf 100644 --- a/src/3rdparty/javascriptcore/runtime/UString.cpp +++ b/src/3rdparty/javascriptcore/runtime/UString.cpp @@ -346,19 +346,14 @@ char* UString::ascii() const static char* asciiBuffer = 0; int length = size(); - int neededSize = length + 1; delete[] asciiBuffer; - asciiBuffer = new char[neededSize]; + asciiBuffer = new char[length + 1]; - const UChar* p = data(); - char* q = asciiBuffer; - const UChar* limit = p + length; - while (p != limit) { - *q = static_cast(p[0]); - ++p; - ++q; + const UChar* d = data(); + for (int i = 0; i < length; i++) { + asciiBuffer[i] = static_cast(d[i]); } - *q = '\0'; + asciiBuffer[length] = '\0'; return asciiBuffer; } -- 2.11.0