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

Commit86d21f1

Browse files
committed
Use LINQ Min and Max methods; don't create second list for methods best matched on defaults
1 parent8581715 commit86d21f1

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

‎src/runtime/methodbinder.cs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,7 @@ internal Binding Bind(IntPtr inst, IntPtr args, IntPtr kw, MethodBase info, Meth
363363
{
364364
// Order matched methods by number of kwargs matched and get the max possible number
365365
// of kwargs matched
366-
varbestKwargMatchCount=argMatchedMethods.OrderBy((x)=>x.KwargsMatched).Reverse().ToArray()[0].KwargsMatched;
366+
varbestKwargMatchCount=argMatchedMethods.Max(x=>x.KwargsMatched);
367367

368368
List<MatchedMethod>bestKwargMatches=newList<MatchedMethod>(argMatchedMethods.Count());
369369
foreach(MatchedMethodtestMatchinargMatchedMethods)
@@ -375,18 +375,21 @@ internal Binding Bind(IntPtr inst, IntPtr args, IntPtr kw, MethodBase info, Meth
375375
}
376376

377377
// Order by the number of defaults required and find the smallest
378-
varfewestDefaultsRequired=bestKwargMatches.OrderBy((x)=>x.DefaultsNeeded).ToArray()[0].DefaultsNeeded;
378+
varfewestDefaultsRequired=bestKwargMatches.Min(x=>x.DefaultsNeeded);
379+
intbestCount=0;
380+
intbestMatchIndex=-1;
379381

380-
List<MatchedMethod>bestDefaultsMatches=newList<MatchedMethod>(bestKwargMatches.Count());
381382
foreach(MatchedMethodtestMatchinbestKwargMatches)
382383
{
383384
if(testMatch.DefaultsNeeded==fewestDefaultsRequired)
384385
{
385-
bestDefaultsMatches.Add(testMatch);
386+
bestCount++;
387+
if(bestMatchIndex==-1)
388+
bestMatchIndex=bestKwargMatches.IndexOf(testMatch);
386389
}
387390
}
388391

389-
if(bestDefaultsMatches.Count()>1&&fewestDefaultsRequired>0)
392+
if(bestCount>1&&fewestDefaultsRequired>0)
390393
{
391394
// Best effort for determining method to match on gives multiple possible
392395
// matches and we need at least one default argument - bail from this point
@@ -400,7 +403,7 @@ internal Binding Bind(IntPtr inst, IntPtr args, IntPtr kw, MethodBase info, Meth
400403
// in the case of (a) we're done by default. For (b) regardless of which
401404
// method we choose, all arguments are specified _and_ can be converted
402405
// from python to C# so picking any will suffice
403-
MatchedMethodbestMatch=bestDefaultsMatches.ToArray()[0];
406+
MatchedMethodbestMatch=bestKwargMatches.ElementAt(bestMatchIndex);
404407
varmargs=bestMatch.ManagedArgs;
405408
varouts=bestMatch.Outs;
406409
varmi=bestMatch.Method;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp