Skip to content

Commit a933f42

Browse files
a-sivacommit-bot@chromium.org
authored andcommitted
[VM] Use Symbols::Empty() when there is no source for a script instead of creating new empty string objects.
Change-Id: I8ec6702557b07c4c4ede2aece5a3f25b4cde1a5b Reviewed-on: https://dart-review.googlesource.com/c/79060 Reviewed-by: Ryan Macnak <[email protected]> Commit-Queue: Siva Annamalai <[email protected]>
1 parent 72b3131 commit a933f42

File tree

3 files changed

+16
-8
lines changed

3 files changed

+16
-8
lines changed

runtime/vm/compiler/frontend/kernel_translation_helper.cc

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2507,12 +2507,17 @@ String& KernelReaderHelper::SourceTableUriFor(intptr_t index) {
25072507
return H.DartString(reader_.BufferAt(ReaderOffset()), size, Heap::kOld);
25082508
}
25092509

2510-
String& KernelReaderHelper::GetSourceFor(intptr_t index) {
2510+
const String& KernelReaderHelper::GetSourceFor(intptr_t index) {
25112511
AlternativeReadingScope alt(&reader_);
25122512
SetOffset(GetOffsetForSourceInfo(index));
25132513
SkipBytes(ReadUInt()); // skip uri.
25142514
intptr_t size = ReadUInt(); // read source List<byte> size.
2515-
return H.DartString(reader_.BufferAt(ReaderOffset()), size, Heap::kOld);
2515+
ASSERT(size >= 0);
2516+
if (size == 0) {
2517+
return Symbols::Empty();
2518+
} else {
2519+
return H.DartString(reader_.BufferAt(ReaderOffset()), size, Heap::kOld);
2520+
}
25162521
}
25172522

25182523
RawTypedData* KernelReaderHelper::GetLineStartsFor(intptr_t index) {

runtime/vm/compiler/frontend/kernel_translation_helper.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1028,7 +1028,7 @@ class KernelReaderHelper {
10281028
intptr_t SourceTableSize();
10291029
intptr_t GetOffsetForSourceInfo(intptr_t index);
10301030
String& SourceTableUriFor(intptr_t index);
1031-
String& GetSourceFor(intptr_t index);
1031+
const String& GetSourceFor(intptr_t index);
10321032
RawTypedData* GetLineStartsFor(intptr_t index);
10331033

10341034
Zone* zone_;

runtime/vm/kernel_loader.cc

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1776,11 +1776,12 @@ const Object& KernelLoader::ClassForScriptAt(const Class& klass,
17761776

17771777
RawScript* KernelLoader::LoadScriptAt(intptr_t index) {
17781778
const String& uri_string = helper_.SourceTableUriFor(index);
1779-
String& sources = helper_.GetSourceFor(index);
1779+
const String& script_source = helper_.GetSourceFor(index);
1780+
String& sources = String::Handle(Z);
17801781
TypedData& line_starts =
17811782
TypedData::Handle(Z, helper_.GetLineStartsFor(index));
1782-
if (sources.Length() == 0 && line_starts.Length() == 0 &&
1783-
uri_string.Length() > 0) {
1783+
if (script_source.raw() == Symbols::Empty().raw() &&
1784+
line_starts.Length() == 0 && uri_string.Length() > 0) {
17841785
// Entry included only to provide URI - actual source should already exist
17851786
// in the VM, so try to find it.
17861787
Library& lib = Library::Handle(Z);
@@ -1796,6 +1797,8 @@ RawScript* KernelLoader::LoadScriptAt(intptr_t index) {
17961797
break;
17971798
}
17981799
}
1800+
} else {
1801+
sources = script_source.raw();
17991802
}
18001803

18011804
const Script& script = Script::Handle(
@@ -1805,8 +1808,8 @@ RawScript* KernelLoader::LoadScriptAt(intptr_t index) {
18051808
script.set_kernel_script_index(index);
18061809
script.set_kernel_program_info(kernel_program_info_);
18071810
script.set_line_starts(line_starts);
1808-
script.set_debug_positions(Array::Handle(Array::null()));
1809-
script.set_yield_positions(Array::Handle(Array::null()));
1811+
script.set_debug_positions(Array::null_array());
1812+
script.set_yield_positions(Array::null_array());
18101813
return script.raw();
18111814
}
18121815

0 commit comments

Comments
 (0)