Skip to content

Commit

Permalink
Merge pull request #927 from lahma/optimize-scalar-load
Browse files Browse the repository at this point in the history
Optimize YamlScalarNode.Load and YamlMappingNode.Load
  • Loading branch information
EdwardCooke authored Jul 14, 2024
2 parents 66cf6d9 + 7964734 commit 760472f
Show file tree
Hide file tree
Showing 6 changed files with 38,430 additions and 255 deletions.
38,102 changes: 38,102 additions & 0 deletions YamlDotNet.Benchmark/Resources/saltern.yml

Large diffs are not rendered by default.

3 changes: 1 addition & 2 deletions YamlDotNet.Benchmark/YamlStreamBenchmark.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.

using System.IO.Compression;
using BenchmarkDotNet.Attributes;
using YamlDotNet.RepresentationModel;

Expand All @@ -33,7 +32,7 @@ public class YamlStreamBenchmark
[GlobalSetup]
public void Setup()
{
using var reader = new StreamReader(new GZipStream(File.OpenRead("Resources/saltern.yml.gz"), CompressionMode.Decompress));
using var reader = new StreamReader(File.OpenRead("Resources/saltern.yml"));
yamlString = reader.ReadToEnd();
}

Expand Down
39 changes: 39 additions & 0 deletions YamlDotNet/Helpers/DictionaryExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// This file is part of YamlDotNet - A .NET library for YAML.
// Copyright (c) Antoine Aubry and contributors
//
// Permission is hereby granted, free of charge, to any person obtaining a copy of
// this software and associated documentation files (the "Software"), to deal in
// the Software without restriction, including without limitation the rights to
// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
// of the Software, and to permit persons to whom the Software is furnished to do
// so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.

namespace YamlDotNet.Helpers
{
internal static class DictionaryExtensions
{
#if NETSTANDARD2_0 || NETFRAMEWORK
public static bool TryAdd<T, V>(this System.Collections.Generic.Dictionary<T, V> dictionary, T key, V value)
{
if (dictionary.ContainsKey(key))
{
return false;
}

dictionary.Add(key, value);
return true;
}
#endif
}
}
Loading

0 comments on commit 760472f

Please sign in to comment.