diff --git a/src/as/com/threerings/presents/dobj/DSet.as b/src/as/com/threerings/presents/dobj/DSet.as index d871e53cb..7ee6545b9 100644 --- a/src/as/com/threerings/presents/dobj/DSet.as +++ b/src/as/com/threerings/presents/dobj/DSet.as @@ -85,7 +85,7 @@ public class DSet */ public function iterator () :Iterator { - return new ArrayIterator(_entries); + return new ArrayIterator(_entries, false); } /** diff --git a/src/as/com/threerings/util/ArrayIterator.as b/src/as/com/threerings/util/ArrayIterator.as index daaa8b52c..3029a2195 100644 --- a/src/as/com/threerings/util/ArrayIterator.as +++ b/src/as/com/threerings/util/ArrayIterator.as @@ -12,10 +12,11 @@ public class ArrayIterator /** * Create an ArrayIterator. */ - public function ArrayIterator (arr :Array) + public function ArrayIterator (arr :Array, allowRemove :Boolean = true) { _arr = arr; _index = 0; + _lastIndex = allowRemove ? -1 : -2; } // documentation inherited from interface Iterator @@ -27,14 +28,16 @@ public class ArrayIterator // documentation inherited from interface Iterator public function next () :Object { - _lastIndex = _index; + if (_lastIndex != -2) { + _lastIndex = _index; + } return _arr[_index++]; } // documentation inherited from interface Iterator public function remove () :void { - if (_lastIndex == -1) { + if (_lastIndex < 0) { throw new IllegalOperationError(); } else { @@ -50,7 +53,8 @@ public class ArrayIterator /** The current index. */ protected var _index :int; - /** The last-removed index. */ - protected var _lastIndex :int = -1; + /** The last-removed index. + * Or -1 for already removed, -2 for no removals allowed. */ + protected var _lastIndex :int; } }