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

Unified Diff: runtime/lib/core_patch.dart

Issue 1682173008: ‘Yield* e' should not access e.current eagerly (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 years, 10 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 | « no previous file | runtime/vm/parser.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/lib/core_patch.dart
diff --git a/runtime/lib/core_patch.dart b/runtime/lib/core_patch.dart
index 224d532c59181cf04341ec7674cd84a3fd158493..11e307af2fe9782aaf8f9f5063f5a55211f91fce 100644
--- a/runtime/lib/core_patch.dart
+++ b/runtime/lib/core_patch.dart
@@ -40,9 +40,13 @@ class _SyncIterable extends IterableBase {
class _SyncIterator implements Iterator {
bool isYieldEach; // Set by generated code for the yield* statement.
Iterator yieldEachIterator;
- var current; // Set by generated code for the yield and yield* statement.
+ var _current; // Set by generated code for the yield and yield* statement.
SyncGeneratorCallback moveNextFn;
+ get current => yieldEachIterator != null
+ ? yieldEachIterator.current
+ : _current;
+
_SyncIterator(this.moveNextFn);
bool moveNext() {
@@ -52,7 +56,6 @@ class _SyncIterator implements Iterator {
while(true) {
if (yieldEachIterator != null) {
if (yieldEachIterator.moveNext()) {
- current = yieldEachIterator.current;
return true;
}
yieldEachIterator = null;
@@ -60,13 +63,14 @@ class _SyncIterator implements Iterator {
isYieldEach = false;
if (!moveNextFn(this)) {
moveNextFn = null;
- current = null;
+ _current = null;
return false;
}
if (isYieldEach) {
Ivan Posva 2016/02/13 07:03:03 Can you please explain in a comment how this code
hausner 2016/02/13 07:13:06 Yes, the generator sets this value when it reaches
Ivan Posva 2016/02/13 07:27:09 I understood the above comment as the field being
// Spec mandates: it is a dynamic error if the class of [the object
// returned by yield*] does not implement Iterable.
- yieldEachIterator = (current as Iterable).iterator;
+ yieldEachIterator = (_current as Iterable).iterator;
+ _current = null;
continue;
}
return true;
« no previous file with comments | « no previous file | runtime/vm/parser.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698