Index: runtime/vm/kernel_reader.cc |
diff --git a/runtime/vm/kernel_reader.cc b/runtime/vm/kernel_reader.cc |
index 11daaa36a57a7e657769d7e3ec2f67d766ef49e0..04aa4140b0b86aac20c5ef27c36c7a5b3a7222fd 100644 |
--- a/runtime/vm/kernel_reader.cc |
+++ b/runtime/vm/kernel_reader.cc |
@@ -435,6 +435,54 @@ const Object& KernelReader::ClassForScriptAt(const dart::Class& klass, |
return klass; |
} |
+static int LowestFirst(const intptr_t* a, const intptr_t* b) { |
+ return *a - *b; |
+} |
+ |
+/** |
+ * If index exists as sublist in list, sort the sublist from lowest to highest, |
+ * then copy it, as Smis and without duplicates, |
+ * to a new Array in Heap::kOld which is returned. |
+ * Otherwise (when sublist doesn't exist in list) return new empty array. |
+ */ |
+static RawArray* AsSortedDuplicateFreeArray( |
+ intptr_t index, |
+ MallocGrowableArray<MallocGrowableArray<intptr_t>*>* list) { |
+ if (index < list->length()) { |
Kevin Millikin (Google)
2017/01/24 13:44:13
Since you've possibly got empty lists for yield po
jensj
2017/01/25 12:52:22
Done.
Though it shouldn't really change anything (
|
+ MallocGrowableArray<intptr_t>* source = list->At(index); |
+ Array& array_object = Array::Handle(); |
+ source->Sort(LowestFirst); |
+ |
+ intptr_t different_values = 0; |
+ intptr_t last_seen = 0; |
+ intptr_t size = source->length(); |
+ for (intptr_t i = 0; i < size; ++i) { |
Kevin Millikin (Google)
2017/01/24 13:44:13
It seems simpler to me to remove the duplicates fr
jensj
2017/01/25 12:52:22
Semi-done.
|
+ intptr_t value = source->At(i); |
+ if (different_values == 0 || last_seen != value) { |
+ last_seen = value; |
+ ++different_values; |
+ } |
+ } |
+ |
+ array_object ^= Array::New(different_values, Heap::kOld); |
+ Smi& smi_value = Smi::Handle(); |
+ different_values = 0; |
+ last_seen = 0; |
+ for (intptr_t i = 0; i < size; ++i) { |
+ intptr_t value = source->At(i); |
+ if (different_values == 0 || last_seen != value) { |
+ smi_value = Smi::New(value); |
+ array_object.SetAt(different_values, smi_value); |
+ last_seen = value; |
+ ++different_values; |
+ } |
+ } |
+ return array_object.raw(); |
+ } else { |
+ return Array::New(0); |
+ } |
+} |
+ |
Script& KernelReader::ScriptAt(intptr_t source_uri_index, String* import_uri) { |
Script& script = Script::ZoneHandle(Z); |
script ^= scripts_.At(source_uri_index); |
@@ -462,6 +510,16 @@ Script& KernelReader::ScriptAt(intptr_t source_uri_index, String* import_uri) { |
array_object.SetAt(i, value); |
} |
script.set_line_starts(array_object); |
+ |
+ // Create tokens_seen array for the script. |
+ array_object ^= AsSortedDuplicateFreeArray( |
+ source_uri_index, &program_->valid_token_positions); |
+ script.set_tokens_seen(array_object); |
+ |
+ // Create yields_seen array for the script. |
+ array_object ^= AsSortedDuplicateFreeArray( |
+ source_uri_index, &program_->yield_token_positions); |
+ script.set_yields_seen(array_object); |
} |
return script; |
} |