public Each ( IronRuby.Runtime.RubyScope scope, |
||
scope | IronRuby.Runtime.RubyScope | |
block | ||
return | object |
public object Each(RubyScope/*!*/ scope, BlockParam/*!*/ block) {
int size = _size ?? _list.Count;
if (size < 0 || size > _list.Count) {
return _list;
}
var result = new object[size];
var values = new object[_list.Count];
_list.CopyTo(values, 0);
var stack = new Stack<State>();
stack.Push(new State(0, 0, true));
while (stack.Count > 0) {
var entry = stack.Pop();
int i = entry.i;
int j = entry.j;
if (entry.init && j == result.Length) {
object blockResult;
if (block.Yield(RubyOps.MakeArrayN(result), out blockResult)) {
return blockResult;
}
} else {
if (!entry.init) {
i++;
}
if (i <= values.Length - result.Length + j) {
result[j] = values[i];
stack.Push(new State(i, j, false));
stack.Push(new State(i + 1, j + 1, true));
}
}
}
return _list;
}
}