diff options
author | Francois Valdy <francois.valdy@gmail.com> | 2015-05-31 13:28:08 +0300 |
---|---|---|
committer | Francois Valdy <francois.valdy@gmail.com> | 2015-06-01 16:33:47 +0300 |
commit | b7e21cd7db215b2d06274c58769a397e53aef3c9 (patch) | |
tree | fa2a002dadeb5bea6b92246788aa427827d2eac5 | |
parent | 8517b47152608c6276bb4824572a51fca29f3247 (diff) |
Faster AssemblyNameReference comparison
- implemented leftover TODO
- faster than forcing FullName generation
-rw-r--r-- | Mono.Cecil/Import.cs | 40 |
1 files changed, 39 insertions, 1 deletions
diff --git a/Mono.Cecil/Import.cs b/Mono.Cecil/Import.cs index 8a3345a..fa5a979 100644 --- a/Mono.Cecil/Import.cs +++ b/Mono.Cecil/Import.cs @@ -759,7 +759,7 @@ namespace Mono.Cecil { for (int i = 0; i < references.Count; i++) { var reference = references [i]; - if (name_reference.FullName != reference.FullName) // TODO compare field by field + if (!Equals (name_reference, reference)) continue; assembly_reference = reference; @@ -769,6 +769,44 @@ namespace Mono.Cecil { assembly_reference = null; return false; } + + private static bool Equals (byte [] a, byte [] b) + { + if (Object.ReferenceEquals (a, b)) + return true; + if (a == null) + return false; + if (a.Length != b.Length) + return false; + for (int i = 0; i < a.Length; i++) + if (a [i] != b [i]) + return false; + return true; + } + + private static bool Equals<T> (T a, T b) where T : class, IEquatable<T> + { + if (Object.ReferenceEquals (a, b)) + return true; + if (a == null) + return false; + return a.Equals (b); + } + + private static bool Equals (AssemblyNameReference a, AssemblyNameReference b) + { + if (Object.ReferenceEquals (a, b)) + return true; + if (a.Name != b.Name) + return false; + if (!Equals (a.Version, b.Version)) + return false; + if (a.Culture != b.Culture) + return false; + if (!Equals (a.PublicKeyToken, b.PublicKeyToken)) + return false; + return true; + } } #endif |