【发布时间】:2009-07-30 06:31:47
【问题描述】:
刚刚在 KeyedCollection.Contains(TKey) 中发现了一个不必要的空检查。
感谢这只是一个很小的优化,但不应该认为这种低效率会被自动代码分析工具发现吗?
这是反射器生成的C#:
public bool Contains(TKey key)
{
if (key == null)
{
ThrowHelper.ThrowArgumentNullException(ExceptionArgument.key);
}
if (this.dict != null)
{
return this.dict.ContainsKey(key);
}
if (key != null) // Not needed as key cannot be null
{
foreach (TItem local in base.Items)
{
if (this.comparer.Equals(this.GetKeyForItem(local), key))
{
return true;
}
}
}
return false;
}
另外,发送补丁的最佳方式是什么? ;-) 通过.net forums 或?
【问题讨论】: