From ce62a947d9b6a362bcc252c9aa0080a5402d7399 Mon Sep 17 00:00:00 2001 From: Vicente Penades Date: Fri, 2 Mar 2018 10:00:41 +0100 Subject: [PATCH] replaced Configuration copy constructor with a ShallowCopy method. --- src/ImageSharp/Configuration.cs | 42 +++++++++++--------- tests/ImageSharp.Tests/ConfigurationTests.cs | 6 ++- 2 files changed, 27 insertions(+), 21 deletions(-) diff --git a/src/ImageSharp/Configuration.cs b/src/ImageSharp/Configuration.cs index 5912ac6309..8d3811a974 100644 --- a/src/ImageSharp/Configuration.cs +++ b/src/ImageSharp/Configuration.cs @@ -33,24 +33,6 @@ namespace SixLabors.ImageSharp { } - /// - /// Initializes a new instance of the class. - /// - /// A configuration instance to be copied - public Configuration(Configuration configuration) - { - this.ParallelOptions = configuration.ParallelOptions; - this.ImageFormatsManager = configuration.ImageFormatsManager; - this.MemoryManager = configuration.MemoryManager; - this.ImageOperationsProvider = configuration.ImageOperationsProvider; - - #if !NETSTANDARD1_1 - this.FileSystem = configuration.FileSystem; - #endif - - this.ReadOrigin = configuration.ReadOrigin; - } - /// /// Initializes a new instance of the class. /// @@ -74,7 +56,7 @@ namespace SixLabors.ImageSharp /// /// Gets the global parallel options for processing tasks in parallel. /// - public ParallelOptions ParallelOptions { get; } = new ParallelOptions { MaxDegreeOfParallelism = Environment.ProcessorCount }; + public ParallelOptions ParallelOptions { get; private set; } = new ParallelOptions { MaxDegreeOfParallelism = Environment.ProcessorCount }; /// /// Gets the currently registered s. @@ -138,6 +120,28 @@ namespace SixLabors.ImageSharp configuration.Configure(this); } + /// + /// Creates a shallow copy of the + /// + /// A new configuration instance + public Configuration ShallowCopy() + { + Configuration cfg = new Configuration(); + + cfg.ParallelOptions = this.ParallelOptions; + cfg.ImageFormatsManager = this.ImageFormatsManager; + cfg.MemoryManager = this.MemoryManager; + cfg.ImageOperationsProvider = this.ImageOperationsProvider; + +#if !NETSTANDARD1_1 + cfg.FileSystem = this.FileSystem; +#endif + + cfg.ReadOrigin = this.ReadOrigin; + + return cfg; + } + /// /// Registers a new format provider. /// diff --git a/tests/ImageSharp.Tests/ConfigurationTests.cs b/tests/ImageSharp.Tests/ConfigurationTests.cs index 06f02fcf16..d38556fa9e 100644 --- a/tests/ImageSharp.Tests/ConfigurationTests.cs +++ b/tests/ImageSharp.Tests/ConfigurationTests.cs @@ -22,8 +22,10 @@ namespace SixLabors.ImageSharp.Tests public Configuration DefaultConfiguration { get; private set; } public ConfigurationTests() - { - this.DefaultConfiguration = Configuration.CreateDefaultInstance(); + { + // the shallow copy of configuration should behave exactly like the default configuration, + // so by using the copy, we test both the default and the copy. + this.DefaultConfiguration = Configuration.CreateDefaultInstance().ShallowCopy(); this.ConfigurationEmpty = new Configuration(); }