This is an automated email from the ASF dual-hosted git repository. nightowl888 pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/lucenenet.git
commit f6addebe128fcfe288e6ce848fa0eed418562468 Author: Shad Storhaug <[email protected]> AuthorDate: Sun Aug 23 23:40:08 2020 +0700 PERFORMANCE: Lucene.Net.Util.AttributeSource: Eliminated unnecessary try catch and replaced ContainsKey with TryGetValue --- src/Lucene.Net/Util/AttributeSource.cs | 19 +++++-------------- 1 file changed, 5 insertions(+), 14 deletions(-) diff --git a/src/Lucene.Net/Util/AttributeSource.cs b/src/Lucene.Net/Util/AttributeSource.cs index e4cf9b1..74fc911 100644 --- a/src/Lucene.Net/Util/AttributeSource.cs +++ b/src/Lucene.Net/Util/AttributeSource.cs @@ -395,28 +395,19 @@ namespace Lucene.Net.Util where T : IAttribute { var attClass = typeof(T); - if (!attributes.ContainsKey(attClass)) + // LUCENENET: Eliminated exception and used TryGetValue + if (!attributes.TryGetValue(attClass, out var result)) { if (!(attClass.IsInterface && typeof(IAttribute).IsAssignableFrom(attClass))) { throw new ArgumentException("AddAttribute() only accepts an interface that extends IAttribute, but " + attClass.FullName + " does not fulfil this contract."); } - AddAttributeImpl(this.factory.CreateAttributeInstance<T>()); + result = this.factory.CreateAttributeInstance<T>(); + AddAttributeImpl(result); } - T returnAttr; - try - { - returnAttr = (T)(IAttribute)attributes[attClass]; - } -#pragma warning disable 168 - catch (KeyNotFoundException knf) -#pragma warning restore 168 - { - return default(T); - } - return returnAttr; + return (T)(IAttribute)result; } /// <summary>
