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

Unified Diff: runtime/vm/object.cc

Issue 2363413004: VM: Avoid allocating strings when disassembling code. (Closed)
Patch Set: addressed comments Created 4 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « runtime/vm/object.h ('k') | runtime/vm/object_service.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/vm/object.cc
diff --git a/runtime/vm/object.cc b/runtime/vm/object.cc
index a368c52bdb2f1d0cc1725961cad6cc3099b3d3b2..d80c2000f1d1a8090cfc71bd0b6300be801c77ff 100644
--- a/runtime/vm/object.cc
+++ b/runtime/vm/object.cc
@@ -11925,8 +11925,8 @@ RawScript* CodeSourceMap::ScriptForPCOffset(const Code& code,
void CodeSourceMap::Dump(const CodeSourceMap& code_source_map,
const Code& code,
const Function& function) {
- const String& code_name = String::Handle(code.QualifiedName());
- THR_Print("Dumping Code Source Map for %s\n", code_name.ToCString());
+ const char* code_name = code.QualifiedName();
+ THR_Print("Dumping Code Source Map for %s\n", code_name);
if (code_source_map.Length() == 0) {
THR_Print("<empty>\n");
return;
@@ -11949,7 +11949,7 @@ void CodeSourceMap::Dump(const CodeSourceMap& code_source_map,
THR_Print("%#-*" Px "\t%s\t%s\n", addr_width,
pc_offset,
tp.ToCString(),
- code_name.ToCString());
+ code_name);
continue;
}
const String& uri = String::Handle(current_script.url());
@@ -14444,7 +14444,7 @@ const char* Code::ToCString() const {
}
-RawString* Code::Name() const {
+const char* Code::Name() const {
const Object& obj = Object::Handle(owner());
if (obj.IsNull()) {
// Regular stub.
@@ -14454,7 +14454,7 @@ RawString* Code::Name() const {
ASSERT(name != NULL);
char* stub_name = OS::SCreate(zone,
"%s%s", Symbols::StubPrefix().ToCString(), name);
- return Symbols::New(thread, stub_name, strlen(stub_name));
+ return stub_name;
} else if (obj.IsClass()) {
// Allocation stub.
Thread* thread = Thread::Current();
@@ -14462,19 +14462,23 @@ RawString* Code::Name() const {
const Class& cls = Class::Cast(obj);
String& cls_name = String::Handle(zone, cls.ScrubbedName());
ASSERT(!cls_name.IsNull());
- return Symbols::FromConcat(thread, Symbols::AllocationStubFor(), cls_name);
+ char* stub_name = OS::SCreate(zone,
+ "%s%s", Symbols::AllocationStubFor().ToCString(), cls_name.ToCString());
+ return stub_name;
} else {
ASSERT(obj.IsFunction());
// Dart function.
- return Function::Cast(obj).UserVisibleName(); // Same as scrubbed name.
+ // Same as scrubbed name.
+ return String::Handle(Function::Cast(obj).UserVisibleName()).ToCString();
}
}
-RawString* Code::QualifiedName() const {
+const char* Code::QualifiedName() const {
const Object& obj = Object::Handle(owner());
if (obj.IsFunction()) {
- return Function::Cast(obj).QualifiedScrubbedName();
+ return String::Handle(
+ Function::Cast(obj).QualifiedScrubbedName()).ToCString();
}
return Name();
}
@@ -16374,32 +16378,6 @@ RawString* AbstractType::BuildName(NameVisibility name_visibility) const {
}
-// Same as user visible name, but including the URI of each occuring type.
-// Used to report errors involving types with identical names.
-//
-// e.g.
-// MyClass<String> -> MyClass<String> where
-// MyClass is from my_uri
-// String is from dart:core
-// MyClass<dynamic, T> -> MyClass<dynamic, T> where
-// MyClass is from my_uri
-// T of OtherClass is from other_uri
-// (MyClass) => int -> (MyClass) => int where
-// MyClass is from my_uri
-// int is from dart:core
-RawString* AbstractType::UserVisibleNameWithURI() const {
- Thread* thread = Thread::Current();
- Zone* zone = thread->zone();
- GrowableHandlePtrArray<const String> pieces(zone, 3);
- pieces.Add(String::Handle(zone, BuildName(kUserVisibleName)));
- if (!IsDynamicType() && !IsVoidType()) {
- pieces.Add(Symbols::SpaceWhereNewLine());
- pieces.Add(String::Handle(zone, EnumerateURIs()));
- }
- return Symbols::FromConcatAll(thread, pieces);
-}
-
-
RawString* AbstractType::ClassName() const {
ASSERT(!IsFunctionType());
if (HasResolvedTypeClass()) {
@@ -20478,7 +20456,7 @@ static int32_t MergeHexCharacters(int32_t c1, int32_t c2) {
}
-RawString* String::EncodeIRI(const String& str) {
+const char* String::EncodeIRI(const String& str) {
const intptr_t len = Utf8::Length(str);
Zone* zone = Thread::Current()->zone();
uint8_t* utf8 = zone->Alloc<uint8_t>(len);
@@ -20490,27 +20468,22 @@ RawString* String::EncodeIRI(const String& str) {
num_escapes += 2;
}
}
- const String& dststr = String::Handle(
- OneByteString::New(len + num_escapes, Heap::kNew));
- {
- intptr_t index = 0;
- for (int i = 0; i < len; ++i) {
- uint8_t byte = utf8[i];
- if (!IsURISafeCharacter(byte)) {
- OneByteString::SetCharAt(dststr, index, '%');
- OneByteString::SetCharAt(dststr, index + 1,
- GetHexCharacter(byte >> 4));
- OneByteString::SetCharAt(dststr, index + 2,
- GetHexCharacter(byte & 0xF));
- index += 3;
- } else {
- ASSERT(byte <= 127);
- OneByteString::SetCharAt(dststr, index, byte);
- index += 1;
- }
+ intptr_t cstr_len = len + num_escapes + 1;
+ char* cstr = zone->Alloc<char>(cstr_len);
+ intptr_t index = 0;
+ for (int i = 0; i < len; ++i) {
+ uint8_t byte = utf8[i];
+ if (!IsURISafeCharacter(byte)) {
+ cstr[index++] = '%';
+ cstr[index++] = GetHexCharacter(byte >> 4);
+ cstr[index++] = GetHexCharacter(byte & 0xF);
+ } else {
+ ASSERT(byte <= 127);
+ cstr[index++] = byte;
}
}
- return dststr.raw();
+ cstr[index] = '\0';
+ return cstr;
}
« no previous file with comments | « runtime/vm/object.h ('k') | runtime/vm/object_service.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698