Browse Source

Eliminate allocation processing the identifier in ProcessApp2Marker

pull/604/head
Jason Nelson 8 years ago
parent
commit
e4bddc786f
  1. 14
      src/ImageSharp/Formats/Jpeg/PdfJsPort/PdfJsJpegDecoderCore.cs

14
src/ImageSharp/Formats/Jpeg/PdfJsPort/PdfJsJpegDecoderCore.cs

@ -482,16 +482,20 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.PdfJsPort
private void ProcessApp2Marker(int remaining) private void ProcessApp2Marker(int remaining)
{ {
// Length is 14 though we only need to check 12. // Length is 14 though we only need to check 12.
const int Icclength = 14; const int IccLength = 14;
if (remaining < Icclength || this.IgnoreMetadata) if (remaining < IccLength || this.IgnoreMetadata)
{ {
this.InputStream.Skip(remaining); this.InputStream.Skip(remaining);
return; return;
} }
byte[] identifier = new byte[Icclength]; #if NETCOREAPP2_1
this.InputStream.Read(identifier, 0, Icclength); byte[] identifier = new byte[IccLength]; // 14 bytes
remaining -= Icclength; // We have read it by this point #else
Span<byte> identifer = stackalloc byte[IccLength];
#endif
this.InputStream.Read(identifier, 0, IccLength);
remaining -= IccLength; // We have read it by this point
if (ProfileResolver.IsProfile(identifier, ProfileResolver.IccMarker)) if (ProfileResolver.IsProfile(identifier, ProfileResolver.IccMarker))
{ {

Loading…
Cancel
Save