Skip to content

Commit 6f11341

Browse files
SimonCroppJimBobSquarePants
authored andcommitted
Cleanup (#965)
* redundant () * redundant stirng interpolation * use method groups * redundant unsafe * redundant qualifiers * redundant () * redundant init * redundant init * redundant casts * redundant casts
1 parent b238317 commit 6f11341

File tree

76 files changed

+252
-252
lines changed

Some content is hidden

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

76 files changed

+252
-252
lines changed

src/ImageSharp.Drawing/Processing/Processors/Drawing/FillRegionProcessor{TPixel}.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ protected override void OnFrameApply(ImageFrame<TPixel> source, Rectangle source
9494
}
9595

9696
float yPlusOne = y + 1;
97-
for (float subPixel = (float)y; subPixel < yPlusOne; subPixel += subpixelFraction)
97+
for (float subPixel = y; subPixel < yPlusOne; subPixel += subpixelFraction)
9898
{
9999
int pointsFound = region.Scan(subPixel + offset, buffer, configuration);
100100
if (pointsFound == 0)
@@ -192,4 +192,4 @@ private bool IsSolidBrushWithoutBlending(out SolidBrush solidBrush)
192192
return this.definition.Options.IsOpaqueColorWithoutBlending(solidBrush.Color);
193193
}
194194
}
195-
}
195+
}

src/ImageSharp.Drawing/Processing/Processors/Text/DrawTextProcessor{TPixel}.cs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -135,21 +135,22 @@ private class CachingGlyphRenderer : IGlyphRenderer, IDisposable
135135

136136
private readonly PathBuilder builder;
137137

138-
private Point currentRenderPosition = default;
139-
private (GlyphRendererParameters glyph, PointF subPixelOffset) currentGlyphRenderParams = default;
140-
private readonly int offset = 0;
141-
private PointF currentPoint = default(PointF);
138+
private Point currentRenderPosition;
139+
private (GlyphRendererParameters glyph, PointF subPixelOffset) currentGlyphRenderParams;
140+
private readonly int offset;
141+
private PointF currentPoint;
142142

143143
private readonly Dictionary<(GlyphRendererParameters glyph, PointF subPixelOffset), GlyphRenderData>
144144
glyphData = new Dictionary<(GlyphRendererParameters glyph, PointF subPixelOffset), GlyphRenderData>();
145145

146-
private readonly bool renderOutline = false;
147-
private readonly bool renderFill = false;
148-
private bool rasterizationRequired = false;
146+
private readonly bool renderOutline;
147+
private readonly bool renderFill;
148+
private bool rasterizationRequired;
149149

150150
public CachingGlyphRenderer(MemoryAllocator memoryAllocator, int size, IPen pen, bool renderFill)
151151
{
152152
this.MemoryAllocator = memoryAllocator;
153+
this.currentRenderPosition = default;
153154
this.Pen = pen;
154155
this.renderFill = renderFill;
155156
this.renderOutline = pen != null;
@@ -326,7 +327,7 @@ private Buffer2D<float> Render(IPath path)
326327
bool scanlineDirty = false;
327328
float yPlusOne = y + 1;
328329

329-
for (float subPixel = (float)y; subPixel < yPlusOne; subPixel += subpixelFraction)
330+
for (float subPixel = y; subPixel < yPlusOne; subPixel += subpixelFraction)
330331
{
331332
var start = new PointF(path.Bounds.Left - 1, subPixel);
332333
var end = new PointF(path.Bounds.Right + 1, subPixel);

src/ImageSharp/Common/Extensions/ConfigurationExtensions.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) Six Labors and contributors.
1+
// Copyright (c) Six Labors and contributors.
22
// Licensed under the Apache License, Version 2.0.
33

44
using System.Threading.Tasks;
@@ -16,7 +16,7 @@ internal static class ConfigurationExtensions
1616
/// </summary>
1717
public static ParallelOptions GetParallelOptions(this Configuration configuration)
1818
{
19-
return new ParallelOptions() { MaxDegreeOfParallelism = configuration.MaxDegreeOfParallelism };
19+
return new ParallelOptions { MaxDegreeOfParallelism = configuration.MaxDegreeOfParallelism };
2020
}
2121
}
22-
}
22+
}

src/ImageSharp/Common/Helpers/Guard.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ public static void DestinationShouldNotBeTooShort<TSource, TDest>(
231231
{
232232
if (destination.Length < source.Length)
233233
{
234-
ThrowArgumentException($"Destination span is too short!", destinationParamName);
234+
ThrowArgumentException("Destination span is too short!", destinationParamName);
235235
}
236236
}
237237

@@ -251,7 +251,7 @@ public static void DestinationShouldNotBeTooShort<TSource, TDest>(
251251
{
252252
if (destination.Length < source.Length)
253253
{
254-
ThrowArgumentException($"Destination span is too short!", destinationParamName);
254+
ThrowArgumentException("Destination span is too short!", destinationParamName);
255255
}
256256
}
257257

src/ImageSharp/Common/ParallelUtils/ParallelHelper.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) Six Labors and contributors.
1+
// Copyright (c) Six Labors and contributors.
22
// Licensed under the Apache License, Version 2.0.
33

44
using System;
@@ -61,7 +61,7 @@ public static void IterateRows(
6161

6262
int verticalStep = DivideCeil(rectangle.Height, numOfSteps);
6363

64-
var parallelOptions = new ParallelOptions() { MaxDegreeOfParallelism = numOfSteps };
64+
var parallelOptions = new ParallelOptions { MaxDegreeOfParallelism = numOfSteps };
6565

6666
Parallel.For(
6767
0,
@@ -109,7 +109,7 @@ public static void IterateRowsWithTempBuffer<T>(
109109

110110
int verticalStep = DivideCeil(rectangle.Height, numOfSteps);
111111

112-
var parallelOptions = new ParallelOptions() { MaxDegreeOfParallelism = numOfSteps };
112+
var parallelOptions = new ParallelOptions { MaxDegreeOfParallelism = numOfSteps };
113113

114114
Parallel.For(
115115
0,
@@ -158,4 +158,4 @@ private static void ValidateRectangle(Rectangle rectangle)
158158
$"{nameof(rectangle)}.{nameof(rectangle.Height)}");
159159
}
160160
}
161-
}
161+
}

src/ImageSharp/Formats/Bmp/BmpFileHeader.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ public static BmpFileHeader Parse(Span<byte> data)
6262
return MemoryMarshal.Cast<byte, BmpFileHeader>(data)[0];
6363
}
6464

65-
public unsafe void WriteTo(Span<byte> buffer)
65+
public void WriteTo(Span<byte> buffer)
6666
{
6767
ref BmpFileHeader dest = ref Unsafe.As<byte, BmpFileHeader>(ref MemoryMarshal.GetReference(buffer));
6868

src/ImageSharp/Formats/Bmp/BmpInfoHeader.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -447,7 +447,7 @@ public void WriteV3Header(Span<byte> buffer)
447447
/// Writes a complete Bitmap V4 header to a buffer.
448448
/// </summary>
449449
/// <param name="buffer">The buffer to write to.</param>
450-
public unsafe void WriteV4Header(Span<byte> buffer)
450+
public void WriteV4Header(Span<byte> buffer)
451451
{
452452
ref BmpInfoHeader dest = ref Unsafe.As<byte, BmpInfoHeader>(ref MemoryMarshal.GetReference(buffer));
453453

src/ImageSharp/Formats/Gif/GifEncoderCore.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ public void Encode<TPixel>(Image<TPixel> image, Stream stream)
8484
bool useGlobalTable = this.colorTableMode == GifColorTableMode.Global;
8585

8686
// Quantize the image returning a palette.
87-
IQuantizedFrame<TPixel> quantized = null;
87+
IQuantizedFrame<TPixel> quantized;
8888
using (IFrameQuantizer<TPixel> frameQuantizer = this.quantizer.CreateFrameQuantizer<TPixel>(image.GetConfiguration()))
8989
{
9090
quantized = frameQuantizer.QuantizeFrame(image.Frames.RootFrame);

src/ImageSharp/Formats/Jpeg/Components/Decoder/HuffmanScanDecoder.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ private void ParseBaselineData()
124124
}
125125
}
126126

127-
private unsafe void ParseBaselineDataInterleaved()
127+
private void ParseBaselineDataInterleaved()
128128
{
129129
// Interleaved
130130
int mcu = 0;
@@ -196,7 +196,7 @@ ref Unsafe.Add(ref blockRef, blockCol),
196196
}
197197
}
198198

199-
private unsafe void ParseBaselineDataNonInterleaved()
199+
private void ParseBaselineDataNonInterleaved()
200200
{
201201
JpegComponent component = this.components[this.frame.ComponentOrder[0]];
202202
ref HuffmanScanBuffer buffer = ref this.scanBuffer;
@@ -366,7 +366,7 @@ ref Unsafe.Add(ref blockRef, blockCol),
366366
}
367367
}
368368

369-
private unsafe void ParseProgressiveDataNonInterleaved()
369+
private void ParseProgressiveDataNonInterleaved()
370370
{
371371
JpegComponent component = this.components[this.frame.ComponentOrder[0]];
372372
ref HuffmanScanBuffer buffer = ref this.scanBuffer;

src/ImageSharp/Formats/Png/PngConstants.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ internal static class PngConstants
5959
/// <summary>
6060
/// The dictionary of available color types.
6161
/// </summary>
62-
public static readonly Dictionary<PngColorType, byte[]> ColorTypes = new Dictionary<PngColorType, byte[]>()
62+
public static readonly Dictionary<PngColorType, byte[]> ColorTypes = new Dictionary<PngColorType, byte[]>
6363
{
6464
[PngColorType.Grayscale] = new byte[] { 1, 2, 4, 8, 16 },
6565
[PngColorType.Rgb] = new byte[] { 8, 16 },

src/ImageSharp/Image.FromBytes.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) Six Labors and contributors.
1+
// Copyright (c) Six Labors and contributors.
22
// Licensed under the Apache License, Version 2.0.
33

44
using System;
@@ -147,7 +147,7 @@ public static IImageFormat DetectFormat(ReadOnlySpan<byte> data)
147147
/// <param name="config">The configuration.</param>
148148
/// <param name="data">The byte array containing encoded image data to read the header from.</param>
149149
/// <returns>The mime type or null if none found.</returns>
150-
public static unsafe IImageFormat DetectFormat(Configuration config, ReadOnlySpan<byte> data)
150+
public static IImageFormat DetectFormat(Configuration config, ReadOnlySpan<byte> data)
151151
{
152152
int maxHeaderSize = config.MaxHeaderSize;
153153
if (maxHeaderSize <= 0)
@@ -351,7 +351,7 @@ public static Image Load(ReadOnlySpan<byte> data, out IImageFormat format) =>
351351
/// <param name="config">The configuration options.</param>
352352
/// <param name="data">The byte span containing image data.</param>
353353
/// <returns>A new <see cref="Image"/>.</returns>
354-
public static unsafe Image Load(Configuration config, ReadOnlySpan<byte> data) => Load(config, data, out _);
354+
public static Image Load(Configuration config, ReadOnlySpan<byte> data) => Load(config, data, out _);
355355

356356
/// <summary>
357357
/// Load a new instance of <see cref="Image"/> from the given encoded byte span.
@@ -395,4 +395,4 @@ public static unsafe Image Load(
395395
}
396396
}
397397
}
398-
}
398+
}

src/ImageSharp/ImageFrame{TPixel}.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) Six Labors and contributors.
1+
// Copyright (c) Six Labors and contributors.
22
// Licensed under the Apache License, Version 2.0.
33

44
using System;
@@ -267,7 +267,7 @@ internal ImageFrame<TPixel2> CloneAs<TPixel2>(Configuration configuration)
267267
ParallelHelper.IterateRows(
268268
this.Bounds(),
269269
configuration,
270-
(rows) =>
270+
rows =>
271271
{
272272
for (int y = rows.Min; y < rows.Max; y++)
273273
{

src/ImageSharp/Memory/Buffer2DExtensions.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public static unsafe void CopyColumns<T>(
4141

4242
fixed (byte* ptr = span)
4343
{
44-
byte* basePtr = (byte*)ptr;
44+
byte* basePtr = ptr;
4545
for (int y = 0; y < buffer.Height; y++)
4646
{
4747
byte* sPtr = basePtr + sOffset;
@@ -184,4 +184,4 @@ private static void CheckColumnRegionsDoNotOverlap<T>(
184184
}
185185
}
186186
}
187-
}
187+
}

src/ImageSharp/MetaData/Profiles/Exif/ExifWriter.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) Six Labors and contributors.
1+
// Copyright (c) Six Labors and contributors.
22
// Licensed under the Apache License, Version 2.0.
33

44
using System;
@@ -53,12 +53,12 @@ public byte[] GetData()
5353

5454
if (this.exifIndexes.Count > 0)
5555
{
56-
exifIndex = (int)this.GetIndex(this.ifdIndexes, ExifTag.SubIFDOffset);
56+
exifIndex = this.GetIndex(this.ifdIndexes, ExifTag.SubIFDOffset);
5757
}
5858

5959
if (this.gpsIndexes.Count > 0)
6060
{
61-
gpsIndex = (int)this.GetIndex(this.ifdIndexes, ExifTag.GPSIFDOffset);
61+
gpsIndex = this.GetIndex(this.ifdIndexes, ExifTag.GPSIFDOffset);
6262
}
6363

6464
uint ifdLength = 2 + this.GetLength(this.ifdIndexes) + 4;
@@ -125,7 +125,7 @@ public byte[] GetData()
125125
i = this.WriteData(startIndex, this.gpsIndexes, result, i);
126126
}
127127

128-
WriteUInt16((ushort)0, result, i);
128+
WriteUInt16(0, result, i);
129129

130130
return result;
131131
}
@@ -373,4 +373,4 @@ private int WriteValue(ExifValue value, Span<byte> destination, int offset)
373373
return this.WriteValue(value.DataType, value.Value, destination, offset);
374374
}
375375
}
376-
}
376+
}

src/ImageSharp/Primitives/ColorMatrix.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) Six Labors and contributors.
1+
// Copyright (c) Six Labors and contributors.
22
// Licensed under the Apache License, Version 2.0.
33

44
#pragma warning disable SA1117 // Parameters should be on same line or separate lines
@@ -269,7 +269,7 @@ public bool IsIdentity
269269
/// </summary>
270270
/// <param name="value">The source matrix.</param>
271271
/// <returns>The negated matrix.</returns>
272-
public static unsafe ColorMatrix operator -(ColorMatrix value)
272+
public static ColorMatrix operator -(ColorMatrix value)
273273
{
274274
ColorMatrix m;
275275

@@ -456,4 +456,4 @@ public override string ToString()
456456
this.M51.ToString(ci), this.M52.ToString(ci), this.M53.ToString(ci), this.M54.ToString(ci));
457457
}
458458
}
459-
}
459+
}

src/ImageSharp/Processing/KnownFilterMatrices.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) Six Labors and contributors.
1+
// Copyright (c) Six Labors and contributors.
22
// Licensed under the Apache License, Version 2.0.
33

44
using System;
@@ -141,7 +141,7 @@ public static class KnownFilterMatrices
141141
/// <summary>
142142
/// Gets an approximated black and white filter
143143
/// </summary>
144-
public static ColorMatrix BlackWhiteFilter { get; } = new ColorMatrix()
144+
public static ColorMatrix BlackWhiteFilter { get; } = new ColorMatrix
145145
{
146146
M11 = 1.5F,
147147
M12 = 1.5F,

src/ImageSharp/Processing/Processors/Normalization/AdaptiveHistogramEqualizationProcessor{TPixel}.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ protected override void OnFrameApply(ImageFrame<TPixel> source, Rectangle source
7474
Parallel.For(
7575
0,
7676
tileYStartPositions.Count,
77-
new ParallelOptions() { MaxDegreeOfParallelism = configuration.MaxDegreeOfParallelism },
77+
new ParallelOptions { MaxDegreeOfParallelism = configuration.MaxDegreeOfParallelism },
7878
index =>
7979
{
8080
int cdfX = 0;
@@ -470,7 +470,7 @@ public void CalculateLookupTables(ImageFrame<TPixel> source, HistogramEqualizati
470470
Parallel.For(
471471
0,
472472
this.tileYStartPositions.Count,
473-
new ParallelOptions() { MaxDegreeOfParallelism = this.configuration.MaxDegreeOfParallelism },
473+
new ParallelOptions { MaxDegreeOfParallelism = this.configuration.MaxDegreeOfParallelism },
474474
index =>
475475
{
476476
int cdfX = 0;

src/ImageSharp/Processing/Processors/Normalization/AdaptiveHistogramEqualizationSlidingWindowProcessor{TPixel}.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ protected override void OnFrameApply(ImageFrame<TPixel> source, Rectangle source
5050
{
5151
MemoryAllocator memoryAllocator = configuration.MemoryAllocator;
5252

53-
var parallelOptions = new ParallelOptions() { MaxDegreeOfParallelism = configuration.MaxDegreeOfParallelism };
53+
var parallelOptions = new ParallelOptions { MaxDegreeOfParallelism = configuration.MaxDegreeOfParallelism };
5454
int tileWidth = source.Width / this.Tiles;
5555
int tileHeight = tileWidth;
5656
int pixelInTile = tileWidth * tileHeight;

tests/ImageSharp.Benchmarks/Codecs/Jpeg/BlockOperations/Block8x8F_Round.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) Six Labors and contributors.
1+
// Copyright (c) Six Labors and contributors.
22
// Licensed under the Apache License, Version 2.0.
33

44
// ReSharper disable InconsistentNaming
@@ -15,7 +15,7 @@ namespace SixLabors.ImageSharp.Benchmarks.Codecs.Jpeg.BlockOperations
1515
{
1616
public class Block8x8F_Round
1717
{
18-
private Block8x8F block = default(Block8x8F);
18+
private Block8x8F block;
1919

2020
[GlobalSetup]
2121
public void Setup()
@@ -66,4 +66,4 @@ public void SimdRound()
6666
row7 = SimdUtils.FastRound(row7);
6767
}
6868
}
69-
}
69+
}

tests/ImageSharp.Benchmarks/Codecs/Jpeg/DecodeJpegParseStreamOnly.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) Six Labors and contributors.
1+
// Copyright (c) Six Labors and contributors.
22
// Licensed under the Apache License, Version 2.0.
33

44
using BenchmarkDotNet.Attributes;
@@ -42,7 +42,7 @@ public void ParseStreamPdfJs()
4242
{
4343
using (var memoryStream = new MemoryStream(this.jpegBytes))
4444
{
45-
var decoder = new JpegDecoderCore(Configuration.Default, new Formats.Jpeg.JpegDecoder() { IgnoreMetadata = true });
45+
var decoder = new JpegDecoderCore(Configuration.Default, new Formats.Jpeg.JpegDecoder { IgnoreMetadata = true });
4646
decoder.ParseStream(memoryStream);
4747
decoder.Dispose();
4848
}
@@ -65,4 +65,4 @@ public void ParseStreamPdfJs()
6565
// | 'System.Drawing FULL' | Core | Core | Jpg/b(...)f.jpg [28] | 17.68 ms | 2.711 ms | 0.1486 ms | 1.00 | 0.00 | 343.7500 | - | - | 757.04 KB |
6666
// | JpegDecoderCore.ParseStream | Core | Core | Jpg/b(...)f.jpg [28] | 14.27 ms | 3.671 ms | 0.2012 ms | 0.81 | 0.00 | - | - | - | 11.76 KB |
6767
}
68-
}
68+
}

0 commit comments

Comments
 (0)