OSDN Git Service

use loop instead of while iterator in UString::ascii()
authorIvailo Monev <xakepa10@laimg.moc>
Wed, 31 Jul 2019 19:15:59 +0000 (19:15 +0000)
committerIvailo Monev <xakepa10@laimg.moc>
Wed, 31 Jul 2019 19:15:59 +0000 (19:15 +0000)
Signed-off-by: Ivailo Monev <xakepa10@laimg.moc>
src/3rdparty/javascriptcore/runtime/UString.cpp

index 74664e3..d6ff802 100644 (file)
@@ -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<char>(p[0]);
-        ++p;
-        ++q;
+    const UChar* d = data();
+    for (int i = 0; i < length; i++) {
+        asciiBuffer[i] = static_cast<char>(d[i]);
     }
-    *q = '\0';
+    asciiBuffer[length] = '\0';
 
     return asciiBuffer;
 }