@@ -376,7 +376,6 @@ void KernelLoader::InitializeFields(UriToSourceTable* uri_to_source_table) {
376
376
const intptr_t source_table_size = helper_.SourceTableSize ();
377
377
const Array& scripts =
378
378
Array::Handle (Z, Array::New (source_table_size, Heap::kOld ));
379
- patch_classes_ = Array::New (source_table_size, Heap::kOld );
380
379
381
380
// Copy the Kernel string offsets out of the binary and into the VM's heap.
382
381
ASSERT (program_->string_table_offset () >= 0 );
@@ -489,11 +488,7 @@ KernelLoader::KernelLoader(const Script& script,
489
488
expression_evaluation_library_(Library::Handle(Z)) {
490
489
ASSERT (T.active_class_ == &active_class_);
491
490
T.finalize_ = false ;
492
-
493
- const Array& scripts = Array::Handle (Z, kernel_program_info_.scripts ());
494
- patch_classes_ = Array::New (scripts.Length (), Heap::kOld );
495
491
library_kernel_data_ = kernel_data.raw ();
496
-
497
492
H.InitFromKernelProgramInfo (kernel_program_info_);
498
493
}
499
494
@@ -2107,6 +2102,13 @@ const Object& KernelLoader::ClassForScriptAt(const Class& klass,
2107
2102
intptr_t source_uri_index) {
2108
2103
const Script& correct_script = Script::Handle (Z, ScriptAt (source_uri_index));
2109
2104
if (klass.script () != correct_script.raw ()) {
2105
+ // Lazily create the [patch_classes_] array in case we need it.
2106
+ if (patch_classes_.IsNull ()) {
2107
+ const Array& scripts = Array::Handle (Z, kernel_program_info_.scripts ());
2108
+ ASSERT (!scripts.IsNull ());
2109
+ patch_classes_ = Array::New (scripts.Length (), Heap::kOld );
2110
+ }
2111
+
2110
2112
// Use cache for patch classes. This works best for in-order usages.
2111
2113
PatchClass& patch_class = PatchClass::ZoneHandle (Z);
2112
2114
patch_class ^= patch_classes_.At (source_uri_index);
0 commit comments