Changeset 30942 in webkit for trunk/JavaScriptCore/kjs/ustring.cpp
- Timestamp:
- Mar 10, 2008, 3:06:44 PM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/kjs/ustring.cpp
r29653 r30942 164 164 165 165 // Hack here to avoid a global with a constructor; point to an unsigned short instead of a UChar. 166 static unsigned short almostUChar;166 static UChar sharedEmptyChar; 167 167 UString::Rep UString::Rep::null = { 0, 0, 1, 0, 0, &UString::Rep::null, 0, 0, 0, 0, 0, 0 }; 168 UString::Rep UString::Rep::empty = { 0, 0, 1, 0, 0, &UString::Rep::empty, 0, reinterpret_cast<UChar*>(&almostUChar), 0, 0, 0, 0 };168 UString::Rep UString::Rep::empty = { 0, 0, 1, 0, 0, &UString::Rep::empty, 0, &sharedEmptyChar, 0, 0, 0, 0 }; 169 169 const int normalStatBufferSize = 4096; 170 170 static char *statBuffer = 0; // FIXME: This buffer is never deallocated. … … 265 265 // Main loop 266 266 for (; l > 0; l--) { 267 hash += s[0] .uc;268 tmp = (s[1] .uc<< 11) ^ hash;267 hash += s[0]; 268 tmp = (s[1] << 11) ^ hash; 269 269 hash = (hash << 16) ^ tmp; 270 270 s += 2; … … 274 274 // Handle end case 275 275 if (rem) { 276 hash += s[0] .uc;276 hash += s[0]; 277 277 hash ^= hash << 11; 278 278 hash += hash >> 17; … … 430 430 else { 431 431 for (size_t i = 0; i < length; i++) 432 d[i] .uc = c[i];432 d[i] = static_cast<unsigned char>(c[i]); // use unsigned char to zero-extend instead of sign-extend 433 433 m_rep = Rep::create(d, static_cast<int>(length)); 434 434 } … … 710 710 } 711 711 712 UString &UString::append(const UString &t)712 UString& UString::append(const UString &t) 713 713 { 714 714 int thisSize = size(); … … 755 755 } 756 756 757 UString &UString::append(const char *t)757 UString& UString::append(const char *t) 758 758 { 759 759 int thisSize = size(); … … 774 774 if (d) { 775 775 for (int i = 0; i < tSize; ++i) 776 d[thisSize + i] = t[i];776 d[thisSize + i] = static_cast<unsigned char>(t[i]); // use unsigned char to zero-extend instead of sign-extend 777 777 m_rep->len = length; 778 778 m_rep->_hash = 0; … … 784 784 if (d) { 785 785 for (int i = 0; i < tSize; ++i) 786 d[thisSize + i] = t[i];786 d[thisSize + i] = static_cast<unsigned char>(t[i]); // use unsigned char to zero-extend instead of sign-extend 787 787 m_rep = Rep::create(m_rep, 0, length); 788 788 } … … 796 796 memcpy(d, data(), thisSize * sizeof(UChar)); 797 797 for (int i = 0; i < tSize; ++i) 798 d[thisSize + i] = t[i];798 d[thisSize + i] = static_cast<unsigned char>(t[i]); // use unsigned char to zero-extend instead of sign-extend 799 799 m_rep = Rep::create(d, length); 800 800 m_rep->capacity = newCapacity; … … 805 805 } 806 806 807 UString &UString::append(unsigned shortc)807 UString& UString::append(UChar c) 808 808 { 809 809 int thisOffset = m_rep->offset; … … 880 880 const UChar *limit = p + length; 881 881 while (p != limit) { 882 *q = static_cast<char>(p ->uc);882 *q = static_cast<char>(p[0]); 883 883 ++p; 884 884 ++q; … … 889 889 } 890 890 891 UString &UString::operator=(const char *c)891 UString& UString::operator=(const char *c) 892 892 { 893 893 if (!c) { … … 916 916 } 917 917 for (int i = 0; i < l; i++) 918 d[i] .uc = c[i];918 d[i] = static_cast<unsigned char>(c[i]); // use unsigned char to zero-extend instead of sign-extend 919 919 920 920 return *this; … … 926 926 const UChar *limit = u + size(); 927 927 while (u < limit) { 928 if (u ->uc> 0xFF)928 if (u[0] > 0xFF) 929 929 return false; 930 930 ++u; … … 1069 1069 return 0; 1070 1070 const UChar *p = m_rep->data(); 1071 unsigned short c = p ->unicode();1071 unsigned short c = p[0]; 1072 1072 1073 1073 // If the first digit is 0, only 0 itself is OK. … … 1105 1105 1106 1106 // Get next character. 1107 c = (++p)->unicode();1107 c = *(++p); 1108 1108 } 1109 1109 } … … 1122 1122 int fsizeminusone = (fsz - 1) * sizeof(UChar); 1123 1123 const UChar *fdata = f.data(); 1124 unsigned short fchar = fdata ->uc;1124 unsigned short fchar = fdata[0]; 1125 1125 ++fdata; 1126 1126 for (const UChar *c = data() + pos; c <= end; c++) 1127 if (c ->uc== fchar && !memcmp(c + 1, fdata, fsizeminusone))1127 if (c[0] == fchar && !memcmp(c + 1, fdata, fsizeminusone)) 1128 1128 return static_cast<int>(c - data()); 1129 1129 … … 1216 1216 const UChar *uend = u + s1.size(); 1217 1217 while (u != uend && *s2) { 1218 if (u ->uc!= (unsigned char)*s2)1218 if (u[0] != (unsigned char)*s2) 1219 1219 return false; 1220 1220 s2++; … … 1239 1239 } 1240 1240 if (l < lmin) 1241 return (c1 ->uc < c2->uc);1241 return (c1[0] < c2[0]); 1242 1242 1243 1243 return (l1 < l2); … … 1259 1259 1260 1260 if (l < lmin) 1261 return (c1 ->uc > c2->uc) ? 1 : -1;1261 return (c1[0] > c2[0]) ? 1 : -1; 1262 1262 1263 1263 if (l1 == l2) … … 1275 1275 // Convert to runs of 8-bit characters. 1276 1276 char* p = buffer.data(); 1277 const ::UChar* d = reinterpret_cast<const ::UChar*>(&data()->uc);1277 const UChar* d = reinterpret_cast<const UChar*>(&data()[0]); 1278 1278 ConversionResult result = convertUTF16ToUTF8(&d, d + length, &p, p + buffer.size(), strict); 1279 1279 if (result != conversionOK)
Note:
See TracChangeset
for help on using the changeset viewer.