Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit5a4e669

Browse files
committed
Clean-up simple classes
1 parentf7f2fc0 commit5a4e669

34 files changed

+351
-434
lines changed

‎src/runtime/arrayobject.cs‎

Lines changed: 27 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
usingSystem;
22
usingSystem.Collections;
3-
usingSystem.Reflection;
43

54
namespacePython.Runtime
65
{
@@ -22,13 +21,13 @@ internal override bool CanSubclass()
2221

2322
publicstaticIntPtrtp_new(IntPtrtp,IntPtrargs,IntPtrkw)
2423
{
25-
ArrayObjectself=GetManagedObject(tp)asArrayObject;
24+
varself=GetManagedObject(tp)asArrayObject;
2625
if(Runtime.PyTuple_Size(args)!=1)
2726
{
2827
returnExceptions.RaiseTypeError("array expects 1 argument");
2928
}
3029
IntPtrop=Runtime.PyTuple_GetItem(args,0);
31-
Objectresult;
30+
objectresult;
3231

3332
if(!Converter.ToManaged(op,self.type,outresult,true))
3433
{
@@ -44,11 +43,11 @@ public static IntPtr tp_new(IntPtr tp, IntPtr args, IntPtr kw)
4443

4544
publicstaticIntPtrmp_subscript(IntPtrob,IntPtridx)
4645
{
47-
CLRObjectobj=(CLRObject)ManagedType.GetManagedObject(ob);
48-
Arrayitems=obj.instasArray;
46+
varobj=(CLRObject)GetManagedObject(ob);
47+
varitems=obj.instasArray;
4948
TypeitemType=obj.inst.GetType().GetElementType();
5049
intrank=items.Rank;
51-
intindex=0;
50+
intindex;
5251
objectvalue;
5352

5453
// Note that CLR 1.0 only supports int indexes - methods to
@@ -62,7 +61,7 @@ public static IntPtr mp_subscript(IntPtr ob, IntPtr idx)
6261

6362
if(rank==1)
6463
{
65-
index=(int)Runtime.PyInt_AsLong(idx);
64+
index=Runtime.PyInt_AsLong(idx);
6665

6766
if(Exceptions.ErrorOccurred())
6867
{
@@ -80,33 +79,29 @@ public static IntPtr mp_subscript(IntPtr ob, IntPtr idx)
8079
}
8180
catch(IndexOutOfRangeException)
8281
{
83-
Exceptions.SetError(Exceptions.IndexError,
84-
"array index out of range"
85-
);
82+
Exceptions.SetError(Exceptions.IndexError,"array index out of range");
8683
returnIntPtr.Zero;
8784
}
8885

89-
returnConverter.ToPython(items.GetValue(index),itemType);
86+
returnConverter.ToPython(value,itemType);
9087
}
9188

9289
// Multi-dimensional arrays can be indexed a la: list[1, 2, 3].
9390

9491
if(!Runtime.PyTuple_Check(idx))
9592
{
96-
Exceptions.SetError(Exceptions.TypeError,
97-
"invalid index value"
98-
);
93+
Exceptions.SetError(Exceptions.TypeError,"invalid index value");
9994
returnIntPtr.Zero;
10095
}
10196

10297
intcount=Runtime.PyTuple_Size(idx);
10398

104-
Arrayargs=Array.CreateInstance(typeof(Int32),count);
99+
Arrayargs=newint[count];
105100

106-
for(inti=0;i<count;i++)
101+
for(vari=0;i<count;i++)
107102
{
108103
IntPtrop=Runtime.PyTuple_GetItem(idx,i);
109-
index=(int)Runtime.PyInt_AsLong(op);
104+
index=Runtime.PyInt_AsLong(op);
110105

111106
if(Exceptions.ErrorOccurred())
112107
{
@@ -127,9 +122,7 @@ public static IntPtr mp_subscript(IntPtr ob, IntPtr idx)
127122
}
128123
catch(IndexOutOfRangeException)
129124
{
130-
Exceptions.SetError(Exceptions.IndexError,
131-
"array index out of range"
132-
);
125+
Exceptions.SetError(Exceptions.IndexError,"array index out of range");
133126
returnIntPtr.Zero;
134127
}
135128

@@ -143,11 +136,11 @@ public static IntPtr mp_subscript(IntPtr ob, IntPtr idx)
143136

144137
publicstaticintmp_ass_subscript(IntPtrob,IntPtridx,IntPtrv)
145138
{
146-
CLRObjectobj=(CLRObject)ManagedType.GetManagedObject(ob);
147-
Arrayitems=obj.instasArray;
139+
varobj=(CLRObject)GetManagedObject(ob);
140+
varitems=obj.instasArray;
148141
TypeitemType=obj.inst.GetType().GetElementType();
149142
intrank=items.Rank;
150-
intindex=0;
143+
intindex;
151144
objectvalue;
152145

153146
if(items.IsReadOnly)
@@ -163,7 +156,7 @@ public static int mp_ass_subscript(IntPtr ob, IntPtr idx, IntPtr v)
163156

164157
if(rank==1)
165158
{
166-
index=(int)Runtime.PyInt_AsLong(idx);
159+
index=Runtime.PyInt_AsLong(idx);
167160

168161
if(Exceptions.ErrorOccurred())
169162
{
@@ -182,9 +175,7 @@ public static int mp_ass_subscript(IntPtr ob, IntPtr idx, IntPtr v)
182175
}
183176
catch(IndexOutOfRangeException)
184177
{
185-
Exceptions.SetError(Exceptions.IndexError,
186-
"array index out of range"
187-
);
178+
Exceptions.SetError(Exceptions.IndexError,"array index out of range");
188179
return-1;
189180
}
190181

@@ -199,12 +190,12 @@ public static int mp_ass_subscript(IntPtr ob, IntPtr idx, IntPtr v)
199190

200191
intcount=Runtime.PyTuple_Size(idx);
201192

202-
Arrayargs=Array.CreateInstance(typeof(Int32),count);
193+
Arrayargs=newint[count];
203194

204-
for(inti=0;i<count;i++)
195+
for(vari=0;i<count;i++)
205196
{
206197
IntPtrop=Runtime.PyTuple_GetItem(idx,i);
207-
index=(int)Runtime.PyInt_AsLong(op);
198+
index=Runtime.PyInt_AsLong(op);
208199

209200
if(Exceptions.ErrorOccurred())
210201
{
@@ -226,9 +217,7 @@ public static int mp_ass_subscript(IntPtr ob, IntPtr idx, IntPtr v)
226217
}
227218
catch(IndexOutOfRangeException)
228219
{
229-
Exceptions.SetError(Exceptions.IndexError,
230-
"array index out of range"
231-
);
220+
Exceptions.SetError(Exceptions.IndexError,"array index out of range");
232221
return-1;
233222
}
234223

@@ -242,9 +231,9 @@ public static int mp_ass_subscript(IntPtr ob, IntPtr idx, IntPtr v)
242231

243232
publicstaticintsq_contains(IntPtrob,IntPtrv)
244233
{
245-
CLRObjectobj=(CLRObject)ManagedType.GetManagedObject(ob);
234+
varobj=(CLRObject)GetManagedObject(ob);
246235
TypeitemType=obj.inst.GetType().GetElementType();
247-
IListitems=obj.instasIList;
236+
varitems=obj.instasIList;
248237
objectvalue;
249238

250239
if(!Converter.ToManaged(v,itemType,outvalue,false))
@@ -267,9 +256,9 @@ public static int sq_contains(IntPtr ob, IntPtr v)
267256

268257
publicstaticintmp_length(IntPtrob)
269258
{
270-
CLRObjectself=(CLRObject)ManagedType.GetManagedObject(ob);
271-
Arrayitems=self.instasArray;
259+
varself=(CLRObject)GetManagedObject(ob);
260+
varitems=self.instasArray;
272261
returnitems.Length;
273262
}
274263
}
275-
}
264+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp