-
Notifications
You must be signed in to change notification settings - Fork 466
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve cache performance of MethodFinder.GetAllInstanceMethods #357
Changes from 5 commits
9694023
7e8b550
b3ffa4c
0135114
a5893ed
a6ffe32
857367b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -78,17 +78,14 @@ private static MethodInfo[] MakeFilteredCopy(MethodInfo[] methodsInCache, Bindin | |
|
||
private static object RemoveDuplicates(MethodInfo[] infos) | ||
{ | ||
var uniqueInfos = new Dictionary<MethodInfo, object>(MethodSignatureComparer.Instance); | ||
var uniqueInfos = new HashSet<MethodInfo>(MethodSignatureComparer.Instance); | ||
foreach (var info in infos) | ||
{ | ||
if (!uniqueInfos.ContainsKey(info)) | ||
{ | ||
uniqueInfos.Add(info, null); | ||
} | ||
uniqueInfos.Add(info); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Seeing the call site it looks like this method could be removed and the call site just replaced with:
This code is cruddy because it would have been written pre-.NET 3.5 so before LINQ and HashSet. |
||
var result = new MethodInfo[uniqueInfos.Count]; | ||
uniqueInfos.Keys.CopyTo(result, 0); | ||
uniqueInfos.CopyTo(result, 0); | ||
return result; | ||
} | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -158,4 +158,4 @@ public override int GetHashCode() | |
} | ||
} | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(Unrelated to this change, and I haven't looked at the call sites... but I wonder why this method's declared return type is
object
, instead ofMethodInfo[]
? Do call sites have to cast the return value back toMethodInfo[]
?)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
They get stored into a field
Dictionary<Type, object> cachedMethodInfosByType
, so yes this field should be updated too since there is only one call site of this private method.