private static object[] MakeItems(object o) { var t = o.GetType(); // Only use fast paths if we have an exact tuple/list, otherwise use iter if (t == typeof(PythonTuple)) { return(((PythonTuple)o)._data); } else if (t == typeof(PythonList)) { return(((PythonList)o).GetObjectArray()); } else if (o is string) { string s = (string)o; object[] res = new object[s.Length]; for (int i = 0; i < res.Length; i++) { res[i] = ScriptingRuntimeHelpers.CharToString(s[i]); } return(res); } else if (o is object[] arr) { return(ArrayOps.CopyArray(arr, arr.Length)); } else { PerfTrack.NoteEvent(PerfTrack.Categories.OverAllocate, "TupleOA: " + PythonTypeOps.GetName(o)); List <object> l = new List <object>(); IEnumerator i = PythonOps.GetEnumerator(o); while (i.MoveNext()) { l.Add(i.Current); } return(l.ToArray()); } }
private static object[] MakeItems(object o) { object[] arr; if (o is PythonTuple) { return(((PythonTuple)o)._data); } else if (o is string) { string s = (string)o; object[] res = new object[s.Length]; for (int i = 0; i < res.Length; i++) { res[i] = ScriptingRuntimeHelpers.CharToString(s[i]); } return(res); } else if (o is List) { return(((List)o).GetObjectArray()); } else if ((arr = o as object[]) != null) { return(ArrayOps.CopyArray(arr, arr.Length)); } else { PerfTrack.NoteEvent(PerfTrack.Categories.OverAllocate, "TupleOA: " + PythonTypeOps.GetName(o)); List <object> l = new List <object>(); IEnumerator i = PythonOps.GetEnumerator(o); while (i.MoveNext()) { l.Add(i.Current); } return(l.ToArray()); } }
internal object?[] ToArray() { return(ArrayOps.CopyArray(_data, _data.Length)); }