OLD | NEW |
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 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
85 intptr_t hash = str.Hash(); | 85 intptr_t hash = str.Hash(); |
86 intptr_t index = FindIndex(symbol_table, str, 0, str.Length(), hash); | 86 intptr_t index = FindIndex(symbol_table, str, 0, str.Length(), hash); |
87 ASSERT(symbol_table.At(index) == String::null()); | 87 ASSERT(symbol_table.At(index) == String::null()); |
88 InsertIntoSymbolTable(symbol_table, str, index); | 88 InsertIntoSymbolTable(symbol_table, str, index); |
89 } | 89 } |
90 | 90 |
91 | 91 |
92 RawString* Symbols::New(const char* str) { | 92 RawString* Symbols::New(const char* str) { |
93 intptr_t width = 0; | 93 intptr_t width = 0; |
94 intptr_t len = Utf8::CodePointCount(str, &width); | 94 intptr_t len = Utf8::CodePointCount(str, &width); |
95 intptr_t size = len * width; | |
96 Zone* zone = Isolate::Current()->current_zone(); | 95 Zone* zone = Isolate::Current()->current_zone(); |
97 if (len == 0) { | 96 if (len == 0) { |
98 return Symbols::New(reinterpret_cast<uint8_t*>(NULL), 0); | 97 return Symbols::New(reinterpret_cast<uint8_t*>(NULL), 0); |
99 } else if (width == 1) { | 98 } else if (width == 1) { |
100 uint8_t* characters = reinterpret_cast<uint8_t*>(zone->Allocate(size)); | 99 uint8_t* characters = zone->Alloc<uint8_t>(len); |
101 Utf8::Decode(str, characters, len); | 100 Utf8::Decode(str, characters, len); |
102 return New(characters, len); | 101 return New(characters, len); |
103 } else if (width == 2) { | 102 } else if (width == 2) { |
104 uint16_t* characters = reinterpret_cast<uint16_t*>(zone->Allocate(size)); | 103 uint16_t* characters = zone->Alloc<uint16_t>(len); |
105 Utf8::Decode(str, characters, len); | 104 Utf8::Decode(str, characters, len); |
106 return New(characters, len); | 105 return New(characters, len); |
107 } | 106 } |
108 ASSERT(width == 4); | 107 ASSERT(width == 4); |
109 uint32_t* characters = reinterpret_cast<uint32_t*>(zone->Allocate(size)); | 108 uint32_t* characters = zone->Alloc<uint32_t>(len); |
110 Utf8::Decode(str, characters, len); | 109 Utf8::Decode(str, characters, len); |
111 return New(characters, len); | 110 return New(characters, len); |
112 } | 111 } |
113 | 112 |
114 | 113 |
115 template<typename T> | 114 template<typename T> |
116 RawString* Symbols::New(const T* characters, intptr_t len) { | 115 RawString* Symbols::New(const T* characters, intptr_t len) { |
117 Isolate* isolate = Isolate::Current(); | 116 Isolate* isolate = Isolate::Current(); |
118 ASSERT(isolate != Dart::vm_isolate()); | 117 ASSERT(isolate != Dart::vm_isolate()); |
119 String& symbol = String::Handle(isolate, String::null()); | 118 String& symbol = String::Handle(isolate, String::null()); |
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
292 String& symbol = String::Handle(); | 291 String& symbol = String::Handle(); |
293 symbol ^= symbol_table.At(index); | 292 symbol ^= symbol_table.At(index); |
294 while (!symbol.IsNull() && !symbol.Equals(str, begin_index, len)) { | 293 while (!symbol.IsNull() && !symbol.Equals(str, begin_index, len)) { |
295 index = (index + 1) % table_size; // Move to next element. | 294 index = (index + 1) % table_size; // Move to next element. |
296 symbol ^= symbol_table.At(index); | 295 symbol ^= symbol_table.At(index); |
297 } | 296 } |
298 return index; // Index of symbol if found or slot into which to add symbol. | 297 return index; // Index of symbol if found or slot into which to add symbol. |
299 } | 298 } |
300 | 299 |
301 } // namespace dart | 300 } // namespace dart |
OLD | NEW |