Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/corefx.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRion Williams <rionmonster@gmail.com>2017-03-21 21:58:04 +0300
committerStephen Toub <stoub@microsoft.com>2017-03-21 21:58:04 +0300
commit3d4d8038d1a3f0c56d3046bc7494f30ecc35e67b (patch)
tree86f1df092eb89fdbe0f236cd54c4449e669c07eb /src/System.Private.Xml.Linq
parent9ebea3c459a094487fbe1db8c518a6a4220f9d08 (diff)
Replaced ContainsKey() Calls with TryAdd() Dictionary Calls (#17201)
* Replaced ContainsKey() Calls with TryAdd() Dictionary Calls (Where Applicable) Replaced `ContainsKey()` method calls with the new `TryAdd()` method where applicable. * Reverted `TryAdd()` To Previous Approach Reverted to earlier approach to avoid unnessary allocation of a new row. * Cleaned Up `else-if` Usage with `TryAdd()` Removed the `TryAdd()` call from within the conditional statements and moved them to the body * Added Extra Line for Readability / Coding Style * Updated Non-Dictionary Test Cases To Use `TryAdd()` Updated various unit tests to include the `TryAdd()` instead of the previous `ContainsKey()` pattern. This focused primarily on test casts that were not dictionary-related at all to help curb any potential regression issues. * Added `TryAdd()` Within Dictionary Performance Test Replaced older `ContainsKey()` implementation with newer `TryAdd()`. * Reverted PerfDictionary Test to `ContainsKey()` Usage Changed test to earlier implementation in to make way for .NET Core specific tests using newer API. * Created Separate .NET Core Dictionary Performance Test Copied the existing dictionary performance tests (from `Perf.Dictionary.cs`) and used the newer `TryAdd()` calls; Adjusted the projects test file only include these when targeting .NET Core. * Created Separate .NET Core SQL Manual Test Reverted previous usage of the newer `TryAdd()` method and created a separate .NET Core specific file to to be conditionally included and tested. * Separated .NET Core ILPrinter Test Reverted previous changes involving the `TryAdd()` method and created a seperate file to test this functionality only for .NET Core. * Created Seperate .NET Core Linq TreeManipulation Tests Reverted previous changes to the normal tests and created a seperate test targeting .NET Core with the newer `TryAdd()` usage. * Created Seperate .NET Core xNodeBuilder Test Reverted previous changes to the normal tests and created a seperate test targeting .NET Core with the newer `TryAdd()` usage. * Missed .NET Core Reference for InternalConnectionWrapper * Applied Compilation Condition for InternalConnectionWrapper to Avoid Collisions Applied Compilation Condition for InternalConnectionWrapper to Avoid Collisions (i.e. either build for .NET Core or use the other one for non-Core builds) * Avoiding Another Build Collision with .NET Core Functionality Added a .NET Core compilation constraint for the .NET Core specific ILPrinter class to avoid issues when building (i.e. only build .NET Core or non-Core). * Fixed Yet Another Potential Build Collision with .NET Core Added a .NET Core compilation constraint for the .NET Core specific Performance Dictionary testing class to avoid issues when building (i.e. only build .NET Core or non-Core). * Removed More Potential .NET Core Compilation Collisions Added .NET Core specific constraint to seperate Core and non-Core classes when building * Additional .NET Core Build Collision Fix Added an additional condition to separate .NET Core and non-Core builds. * Added TryAdd Extension Method for Testing Added an extension method to support `TryAdd()` calls within test cases across the solution to avoid code duplication. * Updated Namespace for Dictionary Extension Methods Changed from `System.Collection.Tests` to `System.Collections.Generic` as this wasn't actually a test but rather an extension method. * Removed Previous Duplicate Tests; Added Extension Method Removed Previous Duplicate Tests; Added Extension Method Usage * Updated Extension Method Path Replaced previous relative pathing string with `$(CommonTestPath)` * Added Missing Generic Type Parameters to TryAdd Extension Method * Removed Unnecessary Using Statement * Updated System.Linq.Expressions Tets to use Extension Method Removed .NET Core duplicate tests; Added reference to new extension method (from Common\tests) * Updated System.Private.Xml.Linq .NET Core Tests to Use TryAdd() Updated System.Private.Xml.Linq .NET Core Tests to Use TryAdd() extension method. * Updated System.Collections To Use Dictionary.TryAdd() Extension Method Removed previous .NET Core duplicated code and references * Updated Non-ContainsKey() Tests To Use Extension Method Updated Non-ContainsKey() tests to use the `TryAdd()` extension method approach * Extended TryAdd() Extension Method Updated the existing `TryAdd()` extension method to target any Dictionary related interfaces (as opposed to Dictionary implementations) * Updated References in System.Collections.Test Removed previous .NET Core specific reference; Added extension method availability * Added `TryAdd()` Extension Reference Added the `TryAdd()` extension for some other dictionary tests that rely on an interface (which now supports the `TryAdd()` method). * Removed Explicit .NET Core Compilation Constraint * Fixed Coding Style Issue Fixed Coding Style Issue of a missing blank line following the closing gullwing brace for the if-statement. * Added `<Link>` Section for Extension Method References Updated all of the previously added extension method `<Compile>` sections to include a `<Link>` section to improve formatting. * Added <Link> Section for Dictionary Extensions Added Missing <Link> Section for Dictionary Extensions
Diffstat (limited to 'src/System.Private.Xml.Linq')
-rw-r--r--src/System.Private.Xml.Linq/tests/TreeManipulation/System.Xml.Linq.TreeManipulation.Tests.csproj3
-rw-r--r--src/System.Private.Xml.Linq/tests/TreeManipulation/XAttributeEnumRemove.cs4
-rw-r--r--src/System.Private.Xml.Linq/tests/TreeManipulation/XNodeSequenceRemove.cs4
-rw-r--r--src/System.Private.Xml.Linq/tests/xNodeBuilder/System.Xml.Linq.xNodeBuilder.Tests.csproj5
-rw-r--r--src/System.Private.Xml.Linq/tests/xNodeBuilder/XmlReaderDiff.cs2
5 files changed, 12 insertions, 6 deletions
diff --git a/src/System.Private.Xml.Linq/tests/TreeManipulation/System.Xml.Linq.TreeManipulation.Tests.csproj b/src/System.Private.Xml.Linq/tests/TreeManipulation/System.Xml.Linq.TreeManipulation.Tests.csproj
index 36a8b4e142..6e01214563 100644
--- a/src/System.Private.Xml.Linq/tests/TreeManipulation/System.Xml.Linq.TreeManipulation.Tests.csproj
+++ b/src/System.Private.Xml.Linq/tests/TreeManipulation/System.Xml.Linq.TreeManipulation.Tests.csproj
@@ -10,6 +10,9 @@
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
</PropertyGroup>
<ItemGroup>
+ <Compile Include="$(CommonTestPath)\System\Collections\DictionaryExtensions.cs">
+ <Link>Common\System\Collections\DictionaryExtensions.cs</Link>
+ </Compile>
<Compile Include="AddFirstAddFirstIntoDocument.cs" />
<Compile Include="AddFirstInvalidIntoXDocument.cs" />
<Compile Include="AddFirstSingeNodeAddIntoElement.cs" />
diff --git a/src/System.Private.Xml.Linq/tests/TreeManipulation/XAttributeEnumRemove.cs b/src/System.Private.Xml.Linq/tests/TreeManipulation/XAttributeEnumRemove.cs
index 63cc8e3a65..b970a643ee 100644
--- a/src/System.Private.Xml.Linq/tests/TreeManipulation/XAttributeEnumRemove.cs
+++ b/src/System.Private.Xml.Linq/tests/TreeManipulation/XAttributeEnumRemove.cs
@@ -245,9 +245,9 @@ namespace XLinqTests
var expectedAttrsForParent = new Dictionary<XElement, List<ExpectedValue>>();
foreach (XElement p in parents)
{
- if (p != null && !expectedAttrsForParent.ContainsKey(p))
+ if (p != null)
{
- expectedAttrsForParent.Add(p, p.Attributes().Except(copyAllAttributes.Where(x => x != null)).Select(a => new ExpectedValue(true, a)).ToList());
+ expectedAttrsForParent.TryAdd(p, p.Attributes().Except(copyAllAttributes.Where(x => x != null)).Select(a => new ExpectedValue(true, a)).ToList());
}
}
diff --git a/src/System.Private.Xml.Linq/tests/TreeManipulation/XNodeSequenceRemove.cs b/src/System.Private.Xml.Linq/tests/TreeManipulation/XNodeSequenceRemove.cs
index 1efb29bd4f..ef2ebc1071 100644
--- a/src/System.Private.Xml.Linq/tests/TreeManipulation/XNodeSequenceRemove.cs
+++ b/src/System.Private.Xml.Linq/tests/TreeManipulation/XNodeSequenceRemove.cs
@@ -735,9 +735,9 @@ namespace XLinqTests
var expectedNodesForParent = new Dictionary<XContainer, List<ExpectedValue>>();
foreach (XContainer p in parents)
{
- if (p != null && !expectedNodesForParent.ContainsKey(p))
+ if (p != null)
{
- expectedNodesForParent.Add(p, p.Nodes().Except(toRemoveCopy.Where(x => x != null)).Select(a => new ExpectedValue(!(a is XText), a)).ProcessNodes().ToList());
+ expectedNodesForParent.TryAdd(p, p.Nodes().Except(toRemoveCopy.Where(x => x != null)).Select(a => new ExpectedValue(!(a is XText), a)).ProcessNodes().ToList());
}
}
diff --git a/src/System.Private.Xml.Linq/tests/xNodeBuilder/System.Xml.Linq.xNodeBuilder.Tests.csproj b/src/System.Private.Xml.Linq/tests/xNodeBuilder/System.Xml.Linq.xNodeBuilder.Tests.csproj
index e1f85c3e5b..7ef7bfd746 100644
--- a/src/System.Private.Xml.Linq/tests/xNodeBuilder/System.Xml.Linq.xNodeBuilder.Tests.csproj
+++ b/src/System.Private.Xml.Linq/tests/xNodeBuilder/System.Xml.Linq.xNodeBuilder.Tests.csproj
@@ -10,6 +10,9 @@
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
</PropertyGroup>
<ItemGroup>
+ <Compile Include="$(CommonTestPath)\System\Collections\DictionaryExtensions.cs">
+ <Link>Common\System\Collections\DictionaryExtensions.cs</Link>
+ </Compile>
<Compile Include="CommonTests.cs" />
<Compile Include="EndOfLineHandlingTests.cs" />
<Compile Include="ErrorConditions.cs" />
@@ -29,4 +32,4 @@
<ProjectReference Include="..\XDocument.Test.ModuleCore\XDocument.Test.ModuleCore.csproj" />
</ItemGroup>
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
-</Project> \ No newline at end of file
+</Project>
diff --git a/src/System.Private.Xml.Linq/tests/xNodeBuilder/XmlReaderDiff.cs b/src/System.Private.Xml.Linq/tests/xNodeBuilder/XmlReaderDiff.cs
index c8bb293e5c..57874af220 100644
--- a/src/System.Private.Xml.Linq/tests/xNodeBuilder/XmlReaderDiff.cs
+++ b/src/System.Private.Xml.Linq/tests/xNodeBuilder/XmlReaderDiff.cs
@@ -39,7 +39,7 @@ namespace CoreXml.Test.XLinq
// verify whether we do have duplicate
TestLog.Compare(!IsDuplicate(depth, prefix, ns), String.Format("Duplicate: {0}, {1}", prefix, ns));
// no duplicates, add new one
- if (!_nsStack.ContainsKey(depth)) _nsStack.Add(depth, new Dictionary<string, string>());
+ _nsStack.TryAdd(depth, new Dictionary<string, string>());
_nsStack[depth].Add(prefix, ns);
}