Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(302)

Side by Side Diff: runtime/vm/object.cc

Issue 11365243: Revert OneByteString back to ISO Latin-1 instead of ASCII (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 #include "vm/object.h" 5 #include "vm/object.h"
6 6
7 #include "include/dart_api.h" 7 #include "include/dart_api.h"
8 #include "platform/assert.h" 8 #include "platform/assert.h"
9 #include "vm/assembler.h" 9 #include "vm/assembler.h"
10 #include "vm/bigint_operations.h" 10 #include "vm/bigint_operations.h"
(...skipping 10059 matching lines...) Expand 10 before | Expand all | Expand 10 after
10070 const uint8_t* utf8_array = reinterpret_cast<const uint8_t*>(str); 10070 const uint8_t* utf8_array = reinterpret_cast<const uint8_t*>(str);
10071 return String::New(utf8_array, array_len, space); 10071 return String::New(utf8_array, array_len, space);
10072 } 10072 }
10073 10073
10074 10074
10075 RawString* String::New(const uint8_t* utf8_array, 10075 RawString* String::New(const uint8_t* utf8_array,
10076 intptr_t array_len, 10076 intptr_t array_len,
10077 Heap::Space space) { 10077 Heap::Space space) {
10078 Utf8::Type type; 10078 Utf8::Type type;
10079 intptr_t len = Utf8::CodePointCount(utf8_array, array_len, &type); 10079 intptr_t len = Utf8::CodePointCount(utf8_array, array_len, &type);
10080 if (type == Utf8::kAscii) { 10080 if (type == Utf8::kISOLatin1) {
10081 const String& strobj = String::Handle(OneByteString::New(len, space)); 10081 const String& strobj = String::Handle(OneByteString::New(len, space));
10082 if (len > 0) { 10082 if (len > 0) {
10083 NoGCScope no_gc; 10083 NoGCScope no_gc;
10084 Utf8::DecodeToAscii(utf8_array, array_len, 10084 Utf8::DecodeToISOLatin1(utf8_array, array_len,
10085 OneByteString::CharAddr(strobj, 0), len); 10085 OneByteString::CharAddr(strobj, 0), len);
10086 } 10086 }
10087 return strobj.raw(); 10087 return strobj.raw();
10088 } 10088 }
10089 ASSERT((type == Utf8::kBMP) || (type == Utf8::kSMP)); 10089 ASSERT((type == Utf8::kBMP) || (type == Utf8::kSMP));
10090 const String& strobj = String::Handle(TwoByteString::New(len, space)); 10090 const String& strobj = String::Handle(TwoByteString::New(len, space));
10091 NoGCScope no_gc; 10091 NoGCScope no_gc;
10092 Utf8::DecodeToUTF16(utf8_array, array_len, 10092 Utf8::DecodeToUTF16(utf8_array, array_len,
10093 TwoByteString::CharAddr(strobj, 0), len); 10093 TwoByteString::CharAddr(strobj, 0), len);
10094 return strobj.raw(); 10094 return strobj.raw();
10095 } 10095 }
10096 10096
10097 10097
10098 RawString* String::New(const uint16_t* utf16_array, 10098 RawString* String::New(const uint16_t* utf16_array,
10099 intptr_t array_len, 10099 intptr_t array_len,
10100 Heap::Space space) { 10100 Heap::Space space) {
10101 bool is_one_byte_string = true; 10101 bool is_one_byte_string = true;
10102 for (intptr_t i = 0; i < array_len; ++i) { 10102 for (intptr_t i = 0; i < array_len; ++i) {
10103 if (utf16_array[i] > 0x7F) { 10103 if (utf16_array[i] > 0xFF) {
10104 is_one_byte_string = false; 10104 is_one_byte_string = false;
10105 break; 10105 break;
10106 } 10106 }
10107 } 10107 }
10108 if (is_one_byte_string) { 10108 if (is_one_byte_string) {
10109 return OneByteString::New(utf16_array, array_len, space); 10109 return OneByteString::New(utf16_array, array_len, space);
10110 } 10110 }
10111 return TwoByteString::New(utf16_array, array_len, space); 10111 return TwoByteString::New(utf16_array, array_len, space);
10112 } 10112 }
10113 10113
10114 10114
10115 RawString* String::New(const uint32_t* utf32_array, 10115 RawString* String::New(const uint32_t* utf32_array,
10116 intptr_t array_len, 10116 intptr_t array_len,
10117 Heap::Space space) { 10117 Heap::Space space) {
10118 bool is_one_byte_string = true; 10118 bool is_one_byte_string = true;
10119 intptr_t utf16_len = array_len; 10119 intptr_t utf16_len = array_len;
10120 for (intptr_t i = 0; i < array_len; ++i) { 10120 for (intptr_t i = 0; i < array_len; ++i) {
10121 if (utf32_array[i] > 0x7F) { 10121 if (utf32_array[i] > 0xFF) {
10122 is_one_byte_string = false; 10122 is_one_byte_string = false;
10123 } 10123 }
10124 if (utf32_array[i] > 0xFFFF) { 10124 if (utf32_array[i] > 0xFFFF) {
10125 utf16_len += 1; 10125 utf16_len += 1;
10126 } 10126 }
10127 } 10127 }
10128 if (is_one_byte_string) { 10128 if (is_one_byte_string) {
10129 return OneByteString::New(utf32_array, array_len, space); 10129 return OneByteString::New(utf32_array, array_len, space);
10130 } 10130 }
10131 return TwoByteString::New(utf16_len, utf32_array, array_len, space); 10131 return TwoByteString::New(utf16_len, utf32_array, array_len, space);
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
10192 10192
10193 void String::Copy(const String& dst, intptr_t dst_offset, 10193 void String::Copy(const String& dst, intptr_t dst_offset,
10194 const uint16_t* utf16_array, 10194 const uint16_t* utf16_array,
10195 intptr_t array_len) { 10195 intptr_t array_len) {
10196 ASSERT(dst_offset >= 0); 10196 ASSERT(dst_offset >= 0);
10197 ASSERT(array_len >= 0); 10197 ASSERT(array_len >= 0);
10198 ASSERT(array_len <= (dst.Length() - dst_offset)); 10198 ASSERT(array_len <= (dst.Length() - dst_offset));
10199 if (dst.IsOneByteString()) { 10199 if (dst.IsOneByteString()) {
10200 NoGCScope no_gc; 10200 NoGCScope no_gc;
10201 for (intptr_t i = 0; i < array_len; ++i) { 10201 for (intptr_t i = 0; i < array_len; ++i) {
10202 ASSERT(utf16_array[i] <= 0x7F); 10202 ASSERT(utf16_array[i] <= 0xFF);
10203 *OneByteString::CharAddr(dst, i + dst_offset) = utf16_array[i]; 10203 *OneByteString::CharAddr(dst, i + dst_offset) = utf16_array[i];
10204 } 10204 }
10205 } else { 10205 } else {
10206 ASSERT(dst.IsTwoByteString()); 10206 ASSERT(dst.IsTwoByteString());
10207 NoGCScope no_gc; 10207 NoGCScope no_gc;
10208 if (array_len > 0) { 10208 if (array_len > 0) {
10209 memmove(TwoByteString::CharAddr(dst, dst_offset), 10209 memmove(TwoByteString::CharAddr(dst, dst_offset),
10210 utf16_array, 10210 utf16_array,
10211 array_len * 2); 10211 array_len * 2);
10212 } 10212 }
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
10347 return Symbols::Empty(); 10347 return Symbols::Empty();
10348 } 10348 }
10349 if (begin_index > str.Length()) { 10349 if (begin_index > str.Length()) {
10350 return String::null(); 10350 return String::null();
10351 } 10351 }
10352 String& result = String::Handle(); 10352 String& result = String::Handle();
10353 bool is_one_byte_string = true; 10353 bool is_one_byte_string = true;
10354 intptr_t char_size = str.CharSize(); 10354 intptr_t char_size = str.CharSize();
10355 if (char_size == kTwoByteChar) { 10355 if (char_size == kTwoByteChar) {
10356 for (intptr_t i = begin_index; i < begin_index + length; ++i) { 10356 for (intptr_t i = begin_index; i < begin_index + length; ++i) {
10357 if (str.CharAt(i) > 0x7F) { 10357 if (str.CharAt(i) > 0xFF) {
10358 is_one_byte_string = false; 10358 is_one_byte_string = false;
10359 break; 10359 break;
10360 } 10360 }
10361 } 10361 }
10362 } 10362 }
10363 if (is_one_byte_string) { 10363 if (is_one_byte_string) {
10364 result ^= OneByteString::New(length, space); 10364 result ^= OneByteString::New(length, space);
10365 } else { 10365 } else {
10366 result ^= TwoByteString::New(length, space); 10366 result ^= TwoByteString::New(length, space);
10367 } 10367 }
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
10406 int32_t src = str.CharAt(i); 10406 int32_t src = str.CharAt(i);
10407 int32_t dst = mapping(src); 10407 int32_t dst = mapping(src);
10408 if (src != dst) { 10408 if (src != dst) {
10409 has_mapping = true; 10409 has_mapping = true;
10410 } 10410 }
10411 dst_max = Utils::Maximum(dst_max, dst); 10411 dst_max = Utils::Maximum(dst_max, dst);
10412 } 10412 }
10413 if (!has_mapping) { 10413 if (!has_mapping) {
10414 return str.raw(); 10414 return str.raw();
10415 } 10415 }
10416 if (dst_max <= 0x7F) { 10416 if (dst_max <= 0xFF) {
10417 return OneByteString::Transform(mapping, str, space); 10417 return OneByteString::Transform(mapping, str, space);
10418 } 10418 }
10419 ASSERT(dst_max > 0x7F); 10419 ASSERT(dst_max > 0xFF);
10420 return TwoByteString::Transform(mapping, str, space); 10420 return TwoByteString::Transform(mapping, str, space);
10421 } 10421 }
10422 10422
10423 10423
10424 RawString* String::ToUpperCase(const String& str, Heap::Space space) { 10424 RawString* String::ToUpperCase(const String& str, Heap::Space space) {
10425 // TODO(cshapiro): create a fast-path for OneByteString instances. 10425 // TODO(cshapiro): create a fast-path for OneByteString instances.
10426 return Transform(CaseMapping::ToUpper, str, space); 10426 return Transform(CaseMapping::ToUpper, str, space);
10427 } 10427 }
10428 10428
10429 10429
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
10557 } 10557 }
10558 return OneByteString::raw(result); 10558 return OneByteString::raw(result);
10559 } 10559 }
10560 10560
10561 10561
10562 RawOneByteString* OneByteString::New(const uint16_t* characters, 10562 RawOneByteString* OneByteString::New(const uint16_t* characters,
10563 intptr_t len, 10563 intptr_t len,
10564 Heap::Space space) { 10564 Heap::Space space) {
10565 const String& result =String::Handle(OneByteString::New(len, space)); 10565 const String& result =String::Handle(OneByteString::New(len, space));
10566 for (intptr_t i = 0; i < len; ++i) { 10566 for (intptr_t i = 0; i < len; ++i) {
10567 ASSERT(characters[i] <= 0x7F); 10567 ASSERT(characters[i] <= 0xFF);
10568 *CharAddr(result, i) = characters[i]; 10568 *CharAddr(result, i) = characters[i];
10569 } 10569 }
10570 return OneByteString::raw(result); 10570 return OneByteString::raw(result);
10571 } 10571 }
10572 10572
10573 10573
10574 RawOneByteString* OneByteString::New(const uint32_t* characters, 10574 RawOneByteString* OneByteString::New(const uint32_t* characters,
10575 intptr_t len, 10575 intptr_t len,
10576 Heap::Space space) { 10576 Heap::Space space) {
10577 const String& result = String::Handle(OneByteString::New(len, space)); 10577 const String& result = String::Handle(OneByteString::New(len, space));
10578 for (intptr_t i = 0; i < len; ++i) { 10578 for (intptr_t i = 0; i < len; ++i) {
10579 ASSERT(characters[i] <= 0x7F); 10579 ASSERT(characters[i] <= 0xFF);
10580 *CharAddr(result, i) = characters[i]; 10580 *CharAddr(result, i) = characters[i];
10581 } 10581 }
10582 return OneByteString::raw(result); 10582 return OneByteString::raw(result);
10583 } 10583 }
10584 10584
10585 10585
10586 RawOneByteString* OneByteString::New(const String& str, 10586 RawOneByteString* OneByteString::New(const String& str,
10587 Heap::Space space) { 10587 Heap::Space space) {
10588 intptr_t len = str.Length(); 10588 intptr_t len = str.Length();
10589 const String& result = String::Handle(OneByteString::New(len, space)); 10589 const String& result = String::Handle(OneByteString::New(len, space));
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
10623 10623
10624 10624
10625 RawOneByteString* OneByteString::Transform(int32_t (*mapping)(int32_t ch), 10625 RawOneByteString* OneByteString::Transform(int32_t (*mapping)(int32_t ch),
10626 const String& str, 10626 const String& str,
10627 Heap::Space space) { 10627 Heap::Space space) {
10628 ASSERT(!str.IsNull()); 10628 ASSERT(!str.IsNull());
10629 intptr_t len = str.Length(); 10629 intptr_t len = str.Length();
10630 const String& result = String::Handle(OneByteString::New(len, space)); 10630 const String& result = String::Handle(OneByteString::New(len, space));
10631 for (intptr_t i = 0; i < len; ++i) { 10631 for (intptr_t i = 0; i < len; ++i) {
10632 int32_t ch = mapping(str.CharAt(i)); 10632 int32_t ch = mapping(str.CharAt(i));
10633 ASSERT(ch >= 0 && ch <= 0x7F); 10633 ASSERT(ch >= 0 && ch <= 0xFF);
10634 *CharAddr(result, i) = ch; 10634 *CharAddr(result, i) = ch;
10635 } 10635 }
10636 return OneByteString::raw(result); 10636 return OneByteString::raw(result);
10637 } 10637 }
10638 10638
10639 10639
10640 RawTwoByteString* TwoByteString::EscapeSpecialCharacters(const String& str, 10640 RawTwoByteString* TwoByteString::EscapeSpecialCharacters(const String& str,
10641 bool raw_str) { 10641 bool raw_str) {
10642 intptr_t len = str.Length(); 10642 intptr_t len = str.Length();
10643 if (len > 0) { 10643 if (len > 0) {
(...skipping 1369 matching lines...) Expand 10 before | Expand all | Expand 10 after
12013 } 12013 }
12014 return result.raw(); 12014 return result.raw();
12015 } 12015 }
12016 12016
12017 12017
12018 const char* WeakProperty::ToCString() const { 12018 const char* WeakProperty::ToCString() const {
12019 return "_WeakProperty"; 12019 return "_WeakProperty";
12020 } 12020 }
12021 12021
12022 } // namespace dart 12022 } // namespace dart
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698