internal void DoSliceAssign(SliceAssign assign, int size, object value) { int ostart, ostop, ostep; indices(size, out ostart, out ostop, out ostep); DoSliceAssign(assign, ostart, ostop, ostep, value); }
internal void DoSliceAssign(SliceAssign assign, int size, object value) { int ostart, ostop, ostep; indices(size, out ostart, out ostop, out ostep); if (this.step == null) { throw Ops.ValueError("cannot do slice assignment w/ no step"); } DoSliceAssign(assign, ostart, ostop, ostep, value); }
private static void OtherSliceAssign(SliceAssign assign, int start, int stop, int step, object value) { // get enumerable data into a list, and then // do the slice. IEnumerator enumerator = Ops.GetEnumerator(value); List sliceData = new List(); while (enumerator.MoveNext()) { sliceData.AddNoLock(enumerator.Current); } DoSliceAssign(assign, start, stop, step, sliceData); }
private static void DoSliceAssign(SliceAssign assign, int start, int stop, int step, object?value) { // fast paths, if we know the size then we can // do this quickly. if (value is IList list) { int count = PythonOps.GetSliceCount(start, stop, step); ListSliceAssign(assign, start, count, step, list); } else { OtherSliceAssign(assign, start, stop, step, value); } }
private static void SequenceSliceAssign(SliceAssign assign, int start, int n, int step, ISequence lst) { if (lst.GetLength() < n) { throw Ops.ValueError("too few items in the enumerator. need {0}", n); } else if (lst.GetLength() != n) { throw Ops.ValueError("too many items in the enumerator need {0}", n); } for (int i = 0, index = start; i < n; i++, index += step) { assign(index, lst[i]); } }
private static void ListSliceAssign(SliceAssign assign, int start, int n, int step, IList lst) { if (lst.Count < n) { throw Ops.ValueError("too few items in the enumerator. need {0} have {1}", n, lst.Count); } else if (lst.Count != n) { throw Ops.ValueError("too many items in the enumerator need {0} have {1}", n, lst.Count); } for (int i = 0, index = start; i < n; i++, index += step) { assign(index, lst[i]); } }
private static void DoSliceAssign(SliceAssign assign, int start, int stop, int step, object value) { stop = step > 0 ? Math.Max(stop, start) : Math.Min(stop, start); int n = Math.Max(0, (step > 0 ? (stop - start + step - 1) : (stop - start + step + 1)) / step); // fast paths, if we know the size then we can // do this quickly. if (value is IList) { ListSliceAssign(assign, start, n, step, value as IList); } else { OtherSliceAssign(assign, start, stop, step, value); } }
private static void DoSliceAssign(SliceAssign assign, int start, int stop, int step, object value) { int n = (step > 0 ? (stop - start + step - 1) : (stop - start + step + 1)) / step; // fast paths, if we know the size then we can // do this quickly. if (value is IList) { ListSliceAssign(assign, start, n, step, value as IList); } else if (value is ISequence) { SequenceSliceAssign(assign, start, n, step, value as ISequence); } else { OtherSliceAssign(assign, start, stop, step, value); } }
private static void OtherSliceAssign(SliceAssign assign, int start, int stop, int step, object value) { // get enumerable data into a list, and then // do the slice. IEnumerator enumerator = PythonOps.GetEnumerator(value); List sliceData = new List(); while (enumerator.MoveNext()) sliceData.AddNoLock(enumerator.Current); DoSliceAssign(assign, start, stop, step, sliceData); }
private static void ListSliceAssign(SliceAssign assign, int start, int n, int step, IList lst) { if (lst.Count < n) throw PythonOps.ValueError("too few items in the enumerator. need {0} have {1}", n, lst.Count); else if (lst.Count != n) throw PythonOps.ValueError("too many items in the enumerator need {0} have {1}", n, lst.Count); for (int i = 0, index = start; i < n; i++, index += step) { assign(index, lst[i]); } }
internal void DoSliceAssign(SliceAssign assign, int size, object value) { int ostart, ostop, ostep; indices(size, out ostart, out ostop, out ostep); if (this._step == null) throw PythonOps.ValueError("cannot do slice assignment w/ no step"); DoSliceAssign(assign, ostart, ostop, ostep, value); }
private static void SequenceSliceAssign(SliceAssign assign, int start, int n, int step, ISequence lst) { if (lst.__len__() < n) throw PythonOps.ValueError("too few items in the enumerator. need {0}", n); else if (lst.__len__() != n) throw PythonOps.ValueError("too many items in the enumerator need {0}", n); for (int i = 0, index = start; i < n; i++, index += step) { assign(index, lst[i]); } }
internal static void DoSliceAssign(SliceAssign assign, int start, int stop, int step, object value) { int n = (step > 0 ? (stop - start + step - 1) : (stop - start + step + 1)) / step; // fast paths, if we know the size then we can // do this quickly. if (value is IList) { ListSliceAssign(assign, start, n, step, value as IList); } else if (value is ISequence) { SequenceSliceAssign(assign, start, n, step, value as ISequence); } else { OtherSliceAssign(assign, start, stop, step, value); } }