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

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

Issue 11368138: Add some support for the code-point code-unit distinction. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Implemented feedback from patch set 3 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 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
90 ASSERT(symbol_table.At(index) == String::null()); 90 ASSERT(symbol_table.At(index) == String::null());
91 InsertIntoSymbolTable(symbol_table, str, index); 91 InsertIntoSymbolTable(symbol_table, str, index);
92 } 92 }
93 93
94 94
95 RawString* Symbols::New(const char* str) { 95 RawString* Symbols::New(const char* str) {
96 ASSERT(str != NULL); 96 ASSERT(str != NULL);
97 Utf8::Type type; 97 Utf8::Type type;
98 intptr_t str_len = strlen(str); 98 intptr_t str_len = strlen(str);
99 const uint8_t* utf8_array = reinterpret_cast<const uint8_t*>(str); 99 const uint8_t* utf8_array = reinterpret_cast<const uint8_t*>(str);
100 intptr_t len = Utf8::CodePointCount(utf8_array, str_len, &type); 100 intptr_t len = Utf8::CodeUnitCount(utf8_array, str_len, &type);
101 Zone* zone = Isolate::Current()->current_zone(); 101 Zone* zone = Isolate::Current()->current_zone();
102 if (len == 0) { 102 if (len == 0) {
103 return Symbols::New(reinterpret_cast<uint8_t*>(NULL), 0); 103 return Symbols::New(reinterpret_cast<uint8_t*>(NULL), 0);
104 } 104 }
105 if (type == Utf8::kLatin1) { 105 if (type == Utf8::kLatin1) {
106 uint8_t* characters = zone->Alloc<uint8_t>(len); 106 uint8_t* characters = zone->Alloc<uint8_t>(len);
107 Utf8::DecodeToLatin1(utf8_array, str_len, characters, len); 107 Utf8::DecodeToLatin1(utf8_array, str_len, characters, len);
108 return New(characters, len); 108 return New(characters, len);
109 } 109 }
110 ASSERT((type == Utf8::kBMP) || (type == Utf8::kSMP)); 110 ASSERT((type == Utf8::kBMP) || (type == Utf8::kSMP));
(...skipping 30 matching lines...) Expand all
141 symbol.SetHash(hash); // Remember the calculated hash value. 141 symbol.SetHash(hash); // Remember the calculated hash value.
142 InsertIntoSymbolTable(symbol_table, symbol, index); 142 InsertIntoSymbolTable(symbol_table, symbol, index);
143 } 143 }
144 } 144 }
145 ASSERT(symbol.IsSymbol()); 145 ASSERT(symbol.IsSymbol());
146 return symbol.raw(); 146 return symbol.raw();
147 } 147 }
148 148
149 template RawString* Symbols::New(const uint8_t* characters, intptr_t len); 149 template RawString* Symbols::New(const uint8_t* characters, intptr_t len);
150 template RawString* Symbols::New(const uint16_t* characters, intptr_t len); 150 template RawString* Symbols::New(const uint16_t* characters, intptr_t len);
151 template RawString* Symbols::New(const uint32_t* characters, intptr_t len);
152 151
153 152
154 RawString* Symbols::New(const String& str) { 153 RawString* Symbols::New(const String& str) {
155 if (str.IsSymbol()) { 154 if (str.IsSymbol()) {
156 return str.raw(); 155 return str.raw();
157 } 156 }
158 return New(str, 0, str.Length()); 157 return New(str, 0, str.Length());
159 } 158 }
160 159
161 160
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
269 268
270 269
271 template intptr_t Symbols::FindIndex(const Array& symbol_table, 270 template intptr_t Symbols::FindIndex(const Array& symbol_table,
272 const uint8_t* characters, 271 const uint8_t* characters,
273 intptr_t len, 272 intptr_t len,
274 intptr_t hash); 273 intptr_t hash);
275 template intptr_t Symbols::FindIndex(const Array& symbol_table, 274 template intptr_t Symbols::FindIndex(const Array& symbol_table,
276 const uint16_t* characters, 275 const uint16_t* characters,
277 intptr_t len, 276 intptr_t len,
278 intptr_t hash); 277 intptr_t hash);
279 template intptr_t Symbols::FindIndex(const Array& symbol_table,
280 const uint32_t* characters,
281 intptr_t len,
282 intptr_t hash);
283
284 278
285 intptr_t Symbols::FindIndex(const Array& symbol_table, 279 intptr_t Symbols::FindIndex(const Array& symbol_table,
286 const String& str, 280 const String& str,
287 intptr_t begin_index, 281 intptr_t begin_index,
288 intptr_t len, 282 intptr_t len,
289 intptr_t hash) { 283 intptr_t hash) {
290 // Last element of the array is the number of used elements. 284 // Last element of the array is the number of used elements.
291 intptr_t table_size = symbol_table.Length() - 1; 285 intptr_t table_size = symbol_table.Length() - 1;
292 intptr_t index = hash % table_size; 286 intptr_t index = hash % table_size;
293 287
(...skipping 17 matching lines...) Expand all
311 } 305 }
312 306
313 307
314 RawObject* Symbols::GetVMSymbol(intptr_t object_id) { 308 RawObject* Symbols::GetVMSymbol(intptr_t object_id) {
315 ASSERT(IsVMSymbolId(object_id)); 309 ASSERT(IsVMSymbolId(object_id));
316 intptr_t i = (object_id - kMaxPredefinedObjectIds); 310 intptr_t i = (object_id - kMaxPredefinedObjectIds);
317 return (i > 0 && i < Symbols::kMaxId) ? predefined_[i] : Object::null(); 311 return (i > 0 && i < Symbols::kMaxId) ? predefined_[i] : Object::null();
318 } 312 }
319 313
320 } // namespace dart 314 } // namespace dart
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698