Skip to content

Commit 72c5548

Browse files
author
Johannes Bildstein
committed
int ToByteArray, use buffer if available instead of parsing and writing the profile
1 parent 35f6b73 commit 72c5548

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed

src/ImageSharp/MetaData/Profiles/ICC/IccProfile.cs

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -52,17 +52,12 @@ public IccProfile(byte[] data)
5252
/// by making a copy from another ICC profile.
5353
/// </summary>
5454
/// <param name="other">The other ICC profile, where the clone should be made from.</param>
55-
/// <exception cref="System.ArgumentNullException"><paramref name="other"/> is null.</exception>>
55+
/// <exception cref="ArgumentNullException"><paramref name="other"/> is null.</exception>>
5656
public IccProfile(IccProfile other)
5757
{
5858
Guard.NotNull(other, nameof(other));
5959

60-
// TODO: Do we need to copy anything else?
61-
if (other.data != null)
62-
{
63-
this.data = new byte[other.data.Length];
64-
Buffer.BlockCopy(other.data, 0, this.data, 0, other.data.Length);
65-
}
60+
this.data = other.ToByteArray();
6661
}
6762

6863
/// <summary>
@@ -185,8 +180,17 @@ public bool CheckIsValid()
185180
/// <returns>The <see cref="T:byte[]"/></returns>
186181
public byte[] ToByteArray()
187182
{
188-
var writer = new IccWriter();
189-
return writer.Write(this);
183+
if (this.data != null)
184+
{
185+
byte[] copy = new byte[this.data.Length];
186+
Buffer.BlockCopy(this.data, 0, copy, 0, copy.Length);
187+
return copy;
188+
}
189+
else
190+
{
191+
var writer = new IccWriter();
192+
return writer.Write(this);
193+
}
190194
}
191195

192196
private void InitializeHeader()

0 commit comments

Comments
 (0)