Browse Source

Review suggestions

pull/2213/head
Brian Popow 4 years ago
parent
commit
41bef5bdf7
  1. 26
      src/ImageSharp/Metadata/Profiles/IPTC/IptcProfile.cs

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

@ -26,11 +26,6 @@ namespace SixLabors.ImageSharp.Metadata.Profiles.Iptc
/// </summary>
private const byte IptcEnvelopeCodedCharacterSet = 0x5A;
/// <summary>
/// This value marks that UTF-8 encoding is used in application records.
/// </summary>
private static readonly byte[] CodedCharacterSetUtf8Value = { 0x1B, 0x25, 0x47 };
/// <summary>
/// Initializes a new instance of the <see cref="IptcProfile"/> class.
/// </summary>
@ -75,6 +70,11 @@ namespace SixLabors.ImageSharp.Metadata.Profiles.Iptc
}
}
/// <summary>
/// Gets a byte array marking that UTF-8 encoding is used in application records.
/// </summary>
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.
/// <summary>
/// Gets the byte data of the IPTC profile.
/// </summary>
@ -291,16 +291,18 @@ namespace SixLabors.ImageSharp.Metadata.Profiles.Iptc
}
}
private int WriteRecord(int offset, byte[] recordData, IptcRecordNumber recordNumber, byte recordBinaryRepresentation)
private int WriteRecord(int offset, ReadOnlySpan<byte> recordData, IptcRecordNumber recordNumber, byte recordBinaryRepresentation)
{
this.Data[offset++] = IptcTagMarkerByte;
this.Data[offset++] = (byte)recordNumber;
this.Data[offset++] = recordBinaryRepresentation;
this.Data[offset++] = (byte)(recordData.Length >> 8);
this.Data[offset++] = (byte)recordData.Length;
Span<byte> data = this.Data.AsSpan(offset, 5);
data[0] = IptcTagMarkerByte;
data[1] = (byte)recordNumber;
data[2] = recordBinaryRepresentation;
data[3] = (byte)(recordData.Length >> 8);
data[4] = (byte)recordData.Length;
offset += 5;
if (recordData.Length > 0)
{
Buffer.BlockCopy(recordData, 0, this.Data, offset, recordData.Length);
recordData.CopyTo(this.Data.AsSpan(offset));
offset += recordData.Length;
}

Loading…
Cancel
Save