Skip to content

Commit 41bef5b

Browse files
committed
Review suggestions
1 parent 288fb0a commit 41bef5b

File tree

1 file changed

+14
-12
lines changed

1 file changed

+14
-12
lines changed

src/ImageSharp/Metadata/Profiles/IPTC/IptcProfile.cs

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,6 @@ public sealed class IptcProfile : IDeepCloneable<IptcProfile>
2626
/// </summary>
2727
private const byte IptcEnvelopeCodedCharacterSet = 0x5A;
2828

29-
/// <summary>
30-
/// This value marks that UTF-8 encoding is used in application records.
31-
/// </summary>
32-
private static readonly byte[] CodedCharacterSetUtf8Value = { 0x1B, 0x25, 0x47 };
33-
3429
/// <summary>
3530
/// Initializes a new instance of the <see cref="IptcProfile"/> class.
3631
/// </summary>
@@ -75,6 +70,11 @@ private IptcProfile(IptcProfile other)
7570
}
7671
}
7772

73+
/// <summary>
74+
/// Gets a byte array marking that UTF-8 encoding is used in application records.
75+
/// </summary>
76+
private static ReadOnlySpan<byte> CodedCharacterSetUtf8Value => new byte[] { 0x1B, 0x25, 0x47 }; // Uses C#'s optimization to refer to the data segment in the assembly directly, no allocation occurs.
77+
7878
/// <summary>
7979
/// Gets the byte data of the IPTC profile.
8080
/// </summary>
@@ -291,16 +291,18 @@ public void UpdateData()
291291
}
292292
}
293293

294-
private int WriteRecord(int offset, byte[] recordData, IptcRecordNumber recordNumber, byte recordBinaryRepresentation)
294+
private int WriteRecord(int offset, ReadOnlySpan<byte> recordData, IptcRecordNumber recordNumber, byte recordBinaryRepresentation)
295295
{
296-
this.Data[offset++] = IptcTagMarkerByte;
297-
this.Data[offset++] = (byte)recordNumber;
298-
this.Data[offset++] = recordBinaryRepresentation;
299-
this.Data[offset++] = (byte)(recordData.Length >> 8);
300-
this.Data[offset++] = (byte)recordData.Length;
296+
Span<byte> data = this.Data.AsSpan(offset, 5);
297+
data[0] = IptcTagMarkerByte;
298+
data[1] = (byte)recordNumber;
299+
data[2] = recordBinaryRepresentation;
300+
data[3] = (byte)(recordData.Length >> 8);
301+
data[4] = (byte)recordData.Length;
302+
offset += 5;
301303
if (recordData.Length > 0)
302304
{
303-
Buffer.BlockCopy(recordData, 0, this.Data, offset, recordData.Length);
305+
recordData.CopyTo(this.Data.AsSpan(offset));
304306
offset += recordData.Length;
305307
}
306308

0 commit comments

Comments
 (0)