From 0ac93761b4c4ef88baf06f5b284e57a6a9891a37 Mon Sep 17 00:00:00 2001 From: Jason Nelson Date: Tue, 27 Mar 2018 15:41:28 -0700 Subject: [PATCH] Make InvalidTags & Values tags readonly This is a list to avoid list resizes when constructing from another instance --- .../MetaData/Profiles/Exif/ExifProfile.cs | 26 +++++++++---------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/src/ImageSharp/MetaData/Profiles/Exif/ExifProfile.cs b/src/ImageSharp/MetaData/Profiles/Exif/ExifProfile.cs index 82542d2eea..fcedb4a9c9 100644 --- a/src/ImageSharp/MetaData/Profiles/Exif/ExifProfile.cs +++ b/src/ImageSharp/MetaData/Profiles/Exif/ExifProfile.cs @@ -23,12 +23,12 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Exif /// /// The collection of EXIF values /// - private Collection values; + private List values; /// /// The list of invalid EXIF tags /// - private List invalidTags; + private IReadOnlyList invalidTags; /// /// The thumbnail offset position in the byte stream @@ -75,8 +75,9 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Exif this.invalidTags = new List(other.invalidTags); if (other.values != null) { - this.values = new Collection(); - foreach (ExifValue value in other.values) + this.values = new List(other.Values.Count); + + foreach (ExifValue value in other.Values) { this.values.Add(new ExifValue(value)); } @@ -92,21 +93,17 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Exif /// /// Gets or sets which parts will be written when the profile is added to an image. /// - public ExifParts Parts - { - get; - set; - } + public ExifParts Parts { get; set; } /// /// Gets the tags that where found but contained an invalid value. /// - public IEnumerable InvalidTags => this.invalidTags; + public IReadOnlyList InvalidTags => this.invalidTags; /// /// Gets the values of this EXIF profile. /// - public IList Values + public IReadOnlyList Values { get { @@ -195,9 +192,10 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Exif { for (int i = 0; i < this.Values.Count; i++) { - if (this.Values[i].Tag == tag) + if (this.values[i].Tag == tag) { - this.Values[i] = this.Values[i].WithValue(value); + this.values[i] = this.values[i].WithValue(value); + return; } } @@ -263,7 +261,7 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Exif if (this.data == null) { - this.values = new Collection(); + this.values = new List(); return; }