| 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/handles.h" | 7 #include "vm/handles.h" |
| 8 #include "vm/handles_impl.h" | 8 #include "vm/handles_impl.h" |
| 9 #include "vm/hash_table.h" | 9 #include "vm/hash_table.h" |
| 10 #include "vm/isolate.h" | 10 #include "vm/isolate.h" |
| (...skipping 377 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 388 } else if (str2.Length() == 0) { | 388 } else if (str2.Length() == 0) { |
| 389 return New(str1); | 389 return New(str1); |
| 390 } else { | 390 } else { |
| 391 return NewSymbol(ConcatString(str1, str2)); | 391 return NewSymbol(ConcatString(str1, str2)); |
| 392 } | 392 } |
| 393 } | 393 } |
| 394 | 394 |
| 395 | 395 |
| 396 // TODO(srdjan): If this becomes performance critical code, consider looking | 396 // TODO(srdjan): If this becomes performance critical code, consider looking |
| 397 // up symbol from pieces instead of concatenating them first into a big string. | 397 // up symbol from pieces instead of concatenating them first into a big string. |
| 398 RawString* Symbols::FromConcatAll(const GrowableArray<const String*>& strs) { | 398 RawString* Symbols::FromConcatAll( |
| 399 const GrowableHandlePtrArray<const String>& strs) { |
| 399 GrowableArray<const char*> cchars(strs.length()); | 400 GrowableArray<const char*> cchars(strs.length()); |
| 400 GrowableArray<intptr_t> lengths(strs.length()); | 401 GrowableArray<intptr_t> lengths(strs.length()); |
| 401 intptr_t len_sum = 0; | 402 intptr_t len_sum = 0; |
| 402 for (intptr_t i = 0; i < strs.length(); i++) { | 403 for (intptr_t i = 0; i < strs.length(); i++) { |
| 403 const char* to_cstr = strs[i]->ToCString(); | 404 const char* to_cstr = strs[i].ToCString(); |
| 404 intptr_t len = strlen(to_cstr); | 405 intptr_t len = strlen(to_cstr); |
| 405 cchars.Add(to_cstr); | 406 cchars.Add(to_cstr); |
| 406 lengths.Add(len); | 407 lengths.Add(len); |
| 407 len_sum += len; | 408 len_sum += len; |
| 408 } | 409 } |
| 409 | 410 |
| 410 Zone* zone = Thread::Current()->zone(); | 411 Zone* zone = Thread::Current()->zone(); |
| 411 char* buffer = zone->Alloc<char>(len_sum); | 412 char* buffer = zone->Alloc<char>(len_sum); |
| 412 const char* const orig_buffer = buffer; | 413 const char* const orig_buffer = buffer; |
| 413 for (intptr_t i = 0; i < cchars.length(); i++) { | 414 for (intptr_t i = 0; i < cchars.length(); i++) { |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 496 RawObject* Symbols::GetVMSymbol(intptr_t object_id) { | 497 RawObject* Symbols::GetVMSymbol(intptr_t object_id) { |
| 497 ASSERT(IsVMSymbolId(object_id)); | 498 ASSERT(IsVMSymbolId(object_id)); |
| 498 intptr_t i = (object_id - kMaxPredefinedObjectIds); | 499 intptr_t i = (object_id - kMaxPredefinedObjectIds); |
| 499 if ((i > kIllegal) && (i < Symbols::kMaxPredefinedId)) { | 500 if ((i > kIllegal) && (i < Symbols::kMaxPredefinedId)) { |
| 500 return symbol_handles_[i]->raw(); | 501 return symbol_handles_[i]->raw(); |
| 501 } | 502 } |
| 502 return Object::null(); | 503 return Object::null(); |
| 503 } | 504 } |
| 504 | 505 |
| 505 } // namespace dart | 506 } // namespace dart |
| OLD | NEW |