Skip to content

Commit eb8e190

Browse files
Merge branch 'main' into js/proper-segment-integrity-handling
2 parents 4abf307 + 6fc1cc4 commit eb8e190

89 files changed

Lines changed: 1330 additions & 480 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

src/ImageSharp/Advanced/ParallelExecutionSettings.cs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public readonly struct ParallelExecutionSettings
2020
/// </summary>
2121
/// <param name="maxDegreeOfParallelism">
2222
/// The value used for initializing <see cref="ParallelOptions.MaxDegreeOfParallelism"/> when using TPL.
23-
/// Set to <c>-1</c> to leave the degree of parallelism unbounded.
23+
/// If set to <c>-1</c>, there is no limit on the number of concurrently running operations.
2424
/// </param>
2525
/// <param name="minimumPixelsProcessedPerTask">The value for <see cref="MinimumPixelsProcessedPerTask"/>.</param>
2626
/// <param name="memoryAllocator">The <see cref="MemoryAllocator"/>.</param>
@@ -31,7 +31,7 @@ public ParallelExecutionSettings(
3131
{
3232
// Shall be compatible with ParallelOptions.MaxDegreeOfParallelism:
3333
// https://docs.microsoft.com/en-us/dotnet/api/system.threading.tasks.paralleloptions.maxdegreeofparallelism
34-
if (maxDegreeOfParallelism == 0 || maxDegreeOfParallelism < -1)
34+
if (maxDegreeOfParallelism is 0 or < -1)
3535
{
3636
throw new ArgumentOutOfRangeException(nameof(maxDegreeOfParallelism));
3737
}
@@ -49,7 +49,7 @@ public ParallelExecutionSettings(
4949
/// </summary>
5050
/// <param name="maxDegreeOfParallelism">
5151
/// The value used for initializing <see cref="ParallelOptions.MaxDegreeOfParallelism"/> when using TPL.
52-
/// Set to <c>-1</c> to leave the degree of parallelism unbounded.
52+
/// If set to <c>-1</c>, there is no limit on the number of concurrently running operations.
5353
/// </param>
5454
/// <param name="memoryAllocator">The <see cref="MemoryAllocator"/>.</param>
5555
public ParallelExecutionSettings(int maxDegreeOfParallelism, MemoryAllocator memoryAllocator)
@@ -64,7 +64,7 @@ public ParallelExecutionSettings(int maxDegreeOfParallelism, MemoryAllocator mem
6464

6565
/// <summary>
6666
/// Gets the value used for initializing <see cref="ParallelOptions.MaxDegreeOfParallelism"/> when using TPL.
67-
/// A value of <c>-1</c> leaves the degree of parallelism unbounded.
67+
/// A value of <c>-1</c> means there is no limit on the number of concurrently running operations.
6868
/// </summary>
6969
public int MaxDegreeOfParallelism { get; }
7070

@@ -93,12 +93,10 @@ public ParallelExecutionSettings MultiplyMinimumPixelsPerTask(int multiplier)
9393
}
9494

9595
/// <summary>
96-
/// Get the default <see cref="SixLabors.ImageSharp.Advanced.ParallelExecutionSettings"/> for a <see cref="SixLabors.ImageSharp.Configuration"/>
96+
/// Get the default <see cref="ParallelExecutionSettings"/> for a <see cref="Configuration"/>
9797
/// </summary>
9898
/// <param name="configuration">The <see cref="Configuration"/>.</param>
9999
/// <returns>The <see cref="ParallelExecutionSettings"/>.</returns>
100100
public static ParallelExecutionSettings FromConfiguration(Configuration configuration)
101-
{
102-
return new ParallelExecutionSettings(configuration.MaxDegreeOfParallelism, configuration.MemoryAllocator);
103-
}
101+
=> new(configuration.MaxDegreeOfParallelism, configuration.MemoryAllocator);
104102
}

src/ImageSharp/Advanced/ParallelRowIterator.cs

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ public static void IterateRows<T>(
4444
where T : struct, IRowOperation
4545
{
4646
ValidateRectangle(rectangle);
47-
ValidateSettings(parallelSettings);
4847

4948
int top = rectangle.Top;
5049
int bottom = rectangle.Bottom;
@@ -109,7 +108,6 @@ public static void IterateRows<T, TBuffer>(
109108
where TBuffer : unmanaged
110109
{
111110
ValidateRectangle(rectangle);
112-
ValidateSettings(parallelSettings);
113111

114112
int top = rectangle.Top;
115113
int bottom = rectangle.Bottom;
@@ -174,7 +172,6 @@ public static void IterateRowIntervals<T>(
174172
where T : struct, IRowIntervalOperation
175173
{
176174
ValidateRectangle(rectangle);
177-
ValidateSettings(parallelSettings);
178175

179176
int top = rectangle.Top;
180177
int bottom = rectangle.Bottom;
@@ -236,7 +233,6 @@ public static void IterateRowIntervals<T, TBuffer>(
236233
where TBuffer : unmanaged
237234
{
238235
ValidateRectangle(rectangle);
239-
ValidateSettings(parallelSettings);
240236

241237
int top = rectangle.Top;
242238
int bottom = rectangle.Bottom;
@@ -315,35 +311,4 @@ private static void ValidateRectangle(Rectangle rectangle)
315311
0,
316312
$"{nameof(rectangle)}.{nameof(rectangle.Height)}");
317313
}
318-
319-
/// <summary>
320-
/// Validates the supplied <see cref="ParallelExecutionSettings"/>.
321-
/// </summary>
322-
/// <param name="parallelSettings">The execution settings.</param>
323-
/// <exception cref="ArgumentOutOfRangeException">
324-
/// Thrown when <see cref="ParallelExecutionSettings.MaxDegreeOfParallelism"/> or
325-
/// <see cref="ParallelExecutionSettings.MinimumPixelsProcessedPerTask"/> is invalid.
326-
/// </exception>
327-
/// <exception cref="ArgumentNullException">
328-
/// Thrown when <see cref="ParallelExecutionSettings.MemoryAllocator"/> is null.
329-
/// This also guards the public <see cref="ParallelExecutionSettings"/> default value, which bypasses constructor validation.
330-
/// </exception>
331-
private static void ValidateSettings(in ParallelExecutionSettings parallelSettings)
332-
{
333-
// ParallelExecutionSettings is a public struct, so callers can pass default and bypass constructor validation.
334-
if (parallelSettings.MaxDegreeOfParallelism is 0 or < -1)
335-
{
336-
throw new ArgumentOutOfRangeException(
337-
$"{nameof(parallelSettings)}.{nameof(ParallelExecutionSettings.MaxDegreeOfParallelism)}");
338-
}
339-
340-
Guard.MustBeGreaterThan(
341-
parallelSettings.MinimumPixelsProcessedPerTask,
342-
0,
343-
$"{nameof(parallelSettings)}.{nameof(ParallelExecutionSettings.MinimumPixelsProcessedPerTask)}");
344-
345-
Guard.NotNull(
346-
parallelSettings.MemoryAllocator,
347-
$"{nameof(parallelSettings)}.{nameof(ParallelExecutionSettings.MemoryAllocator)}");
348-
}
349314
}

src/ImageSharp/Configuration.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,9 @@ public Configuration(params IImageFormatConfigurationModule[] configurationModul
6565
/// <summary>
6666
/// Gets or sets the maximum number of concurrent tasks enabled in ImageSharp algorithms
6767
/// configured with this <see cref="Configuration"/> instance.
68-
/// Set to <c>-1</c> to leave the degree of parallelism unbounded.
69-
/// Initialized with <see cref="Environment.ProcessorCount"/> by default.
68+
/// A positive value limits the number of concurrent operations to the set value.
69+
/// If set to <c>-1</c>, there is no limit on the number of concurrently running operations.
70+
/// Defaults to <see cref="Environment.ProcessorCount"/>.
7071
/// </summary>
7172
public int MaxDegreeOfParallelism
7273
{

0 commit comments

Comments
 (0)