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

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

Issue 1322973006: Symbols::NewFormatted and old space allocation. (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Address review comment Created 5 years, 3 months 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
« no previous file with comments | « runtime/vm/symbols.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/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 522 matching lines...) Expand 10 before | Expand all | Expand 10 after
533 } 533 }
534 return New(str, 0, str.Length()); 534 return New(str, 0, str.Length());
535 } 535 }
536 536
537 537
538 RawString* Symbols::New(const String& str, intptr_t begin_index, intptr_t len) { 538 RawString* Symbols::New(const String& str, intptr_t begin_index, intptr_t len) {
539 return NewSymbol(StringSlice(str, begin_index, len)); 539 return NewSymbol(StringSlice(str, begin_index, len));
540 } 540 }
541 541
542 542
543
544 RawString* Symbols::NewFormatted(const char* format, ...) {
545 va_list args;
546 va_start(args, format);
547 RawString* result = NewFormattedV(format, args);
548 NoSafepointScope no_safepoint;
549 va_end(args);
550 return result;
551 }
552
553
554 RawString* Symbols::NewFormattedV(const char* format, va_list args) {
555 va_list args_copy;
556 va_copy(args_copy, args);
557 intptr_t len = OS::VSNPrint(NULL, 0, format, args_copy);
558 va_end(args_copy);
559
560 Zone* zone = Thread::Current()->zone();
561 char* buffer = zone->Alloc<char>(len + 1);
562 OS::VSNPrint(buffer, (len + 1), format, args);
563
564 return Symbols::New(buffer);
565 }
566
567
543 RawString* Symbols::FromCharCode(int32_t char_code) { 568 RawString* Symbols::FromCharCode(int32_t char_code) {
544 if (char_code > kMaxOneCharCodeSymbol) { 569 if (char_code > kMaxOneCharCodeSymbol) {
545 return FromUTF32(&char_code, 1); 570 return FromUTF32(&char_code, 1);
546 } 571 }
547 return predefined_[char_code]; 572 return predefined_[char_code];
548 } 573 }
549 574
550 575
551 void Symbols::DumpStats() { 576 void Symbols::DumpStats() {
552 if (FLAG_dump_symbol_stats) { 577 if (FLAG_dump_symbol_stats) {
(...skipping 26 matching lines...) Expand all
579 RawObject* Symbols::GetVMSymbol(intptr_t object_id) { 604 RawObject* Symbols::GetVMSymbol(intptr_t object_id) {
580 ASSERT(IsVMSymbolId(object_id)); 605 ASSERT(IsVMSymbolId(object_id));
581 intptr_t i = (object_id - kMaxPredefinedObjectIds); 606 intptr_t i = (object_id - kMaxPredefinedObjectIds);
582 if ((i > kIllegal) && (i < Symbols::kMaxPredefinedId)) { 607 if ((i > kIllegal) && (i < Symbols::kMaxPredefinedId)) {
583 return symbol_handles_[i]->raw(); 608 return symbol_handles_[i]->raw();
584 } 609 }
585 return Object::null(); 610 return Object::null();
586 } 611 }
587 612
588 } // namespace dart 613 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/symbols.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698