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

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

Issue 11318018: - Represent strings internally in UTF-16 format, this makes it (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/symbols.h" 5 #include "vm/symbols.h"
6 6
7 #include "vm/isolate.h" 7 #include "vm/isolate.h"
8 #include "vm/object.h" 8 #include "vm/object.h"
9 #include "vm/object_store.h" 9 #include "vm/object_store.h"
10 #include "vm/raw_object.h" 10 #include "vm/raw_object.h"
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
87 // Should only be run by the vm isolate. 87 // Should only be run by the vm isolate.
88 ASSERT(Isolate::Current() == Dart::vm_isolate()); 88 ASSERT(Isolate::Current() == Dart::vm_isolate());
89 intptr_t hash = str.Hash(); 89 intptr_t hash = str.Hash();
90 intptr_t index = FindIndex(symbol_table, str, 0, str.Length(), hash); 90 intptr_t index = FindIndex(symbol_table, str, 0, str.Length(), hash);
91 ASSERT(symbol_table.At(index) == String::null()); 91 ASSERT(symbol_table.At(index) == String::null());
92 InsertIntoSymbolTable(symbol_table, str, index); 92 InsertIntoSymbolTable(symbol_table, str, index);
93 } 93 }
94 94
95 95
96 RawString* Symbols::New(const char* str) { 96 RawString* Symbols::New(const char* str) {
97 intptr_t width = 0; 97 ASSERT(str != NULL);
98 intptr_t len = Utf8::CodePointCount(str, &width); 98 Utf8::Type type;
99 intptr_t str_len = strlen(str);
100 const uint8_t* utf8_array = reinterpret_cast<const uint8_t*>(str);
101 intptr_t len = Utf8::CodePointCount(utf8_array, str_len, &type);
99 Zone* zone = Isolate::Current()->current_zone(); 102 Zone* zone = Isolate::Current()->current_zone();
100 if (len == 0) { 103 if (len == 0) {
101 return Symbols::New(reinterpret_cast<uint8_t*>(NULL), 0); 104 return Symbols::New(reinterpret_cast<uint8_t*>(NULL), 0);
102 } else if (width == 1) { 105 }
106 if (type == Utf8::kAscii) {
103 uint8_t* characters = zone->Alloc<uint8_t>(len); 107 uint8_t* characters = zone->Alloc<uint8_t>(len);
104 Utf8::Decode(str, characters, len); 108 Utf8::DecodeToAscii(utf8_array, str_len, characters, len);
105 return New(characters, len);
106 } else if (width == 2) {
107 uint16_t* characters = zone->Alloc<uint16_t>(len);
108 Utf8::Decode(str, characters, len);
109 return New(characters, len); 109 return New(characters, len);
110 } 110 }
111 ASSERT(width == 4); 111 ASSERT((type == Utf8::kBMP) || (type == Utf8::kSMP));
112 uint32_t* characters = zone->Alloc<uint32_t>(len); 112 uint16_t* characters = zone->Alloc<uint16_t>(len);
113 Utf8::Decode(str, characters, len); 113 Utf8::DecodeToUTF16(utf8_array, str_len, characters, len);
114 return New(characters, len); 114 return New(characters, len);
115 } 115 }
116 116
117 117
118 template<typename T> 118 template<typename T>
119 RawString* Symbols::New(const T* characters, intptr_t len) { 119 RawString* Symbols::New(const T* characters, intptr_t len) {
120 Isolate* isolate = Isolate::Current(); 120 Isolate* isolate = Isolate::Current();
121 ASSERT(isolate != Dart::vm_isolate()); 121 ASSERT(isolate != Dart::vm_isolate());
122 String& symbol = String::Handle(isolate, String::null()); 122 String& symbol = String::Handle(isolate, String::null());
123 Array& symbol_table = Array::Handle(isolate, Array::null()); 123 Array& symbol_table = Array::Handle(isolate, Array::null());
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after
312 } 312 }
313 313
314 314
315 RawObject* Symbols::GetVMSymbol(intptr_t object_id) { 315 RawObject* Symbols::GetVMSymbol(intptr_t object_id) {
316 ASSERT(IsVMSymbolId(object_id)); 316 ASSERT(IsVMSymbolId(object_id));
317 intptr_t i = (object_id - kMaxPredefinedObjectIds); 317 intptr_t i = (object_id - kMaxPredefinedObjectIds);
318 return (i > 0 && i < Symbols::kMaxId) ? predefined_[i] : Object::null(); 318 return (i > 0 && i < Symbols::kMaxId) ? predefined_[i] : Object::null();
319 } 319 }
320 320
321 } // namespace dart 321 } // namespace dart
OLDNEW
« runtime/vm/dart_api_impl.cc ('K') | « runtime/vm/symbols.h ('k') | runtime/vm/unicode.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698