Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid allocating empty arrays #302

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/TaglibSharp.Tests/FileFormats/Id3V2FormatTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ public void TestPicturesAreCopied ()
file.Tag.Pictures = new[] { picture };
file.Save ();

Assert.IsTrue (file.Tag.Pictures.Count () == 1, "File should start with 1 picture");
Assert.IsTrue (file.Tag.Pictures.Length == 1, "File should start with 1 picture");

// Now construct a new tag with a title, APIC and GEOB frame

Expand Down Expand Up @@ -187,12 +187,12 @@ public void TestPicturesAreCopied ()
tag.CopyTo (file.Tag, false);

Assert.AreEqual ("MP3 title", file.Tag.Title, "Title shouldn't be copied if overwrite=false");
Assert.AreEqual (1, file.Tag.Pictures.Count (), "GEOB/APIC frames shouldn't be copied if overwrite=false");
Assert.AreEqual (1, file.Tag.Pictures.Length, "GEOB/APIC frames shouldn't be copied if overwrite=false");

tag.CopyTo (file.Tag, true);

Assert.AreEqual (tag.Title, file.Tag.Title, "Title wasn't copied");
Assert.AreEqual (tag.Pictures.Count (), file.Tag.Pictures.Count (), "GEOB/APIC frames weren't copied");
Assert.AreEqual (tag.Pictures.Length, file.Tag.Pictures.Length, "GEOB/APIC frames weren't copied");
}
}
}
4 changes: 2 additions & 2 deletions src/TaglibSharp.Tests/Images/AddImageMetadataTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ public static void AddXMPTest2 (string sample_file, string tmp_file, bool contai
xmp_tag.Comment = null;
xmp_tag.Software = test_comment;

Assert.AreEqual (new string[] { }, xmp_tag.Keywords);
Assert.AreEqual (Array.Empty<string> (), xmp_tag.Keywords);
Assert.AreEqual (null, xmp_tag.Comment);
Assert.AreEqual (test_comment, xmp_tag.Software);

Expand All @@ -119,7 +119,7 @@ public static void AddXMPTest2 (string sample_file, string tmp_file, bool contai
xmp_tag = file.GetTag (TagTypes.XMP, false) as XmpTag;
Assert.IsNotNull (xmp_tag, "XMP Tag not read");

Assert.AreEqual (new string[] { }, xmp_tag.Keywords);
Assert.AreEqual (Array.Empty<string> (), xmp_tag.Keywords);
Assert.AreEqual (null, xmp_tag.Comment);
Assert.AreEqual (test_comment, xmp_tag.Software);
}
Expand Down
8 changes: 4 additions & 4 deletions src/TaglibSharp.Tests/Images/CopyFromTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ public void TestJPGtoTIFF ()
Assert.AreEqual (TagTypes.TiffIFD | TagTypes.XMP, file2.TagTypes);
Assert.AreEqual ("%test comment%", file1.ImageTag.Comment);
Assert.AreEqual (string.Empty, file2.ImageTag.Comment);
Assert.AreEqual (new string[] { }, file1.ImageTag.Keywords);
Assert.AreEqual (new string[] { }, file2.ImageTag.Keywords);
Assert.AreEqual (Array.Empty<string> (), file1.ImageTag.Keywords);
Assert.AreEqual (Array.Empty<string> (), file2.ImageTag.Keywords);
Assert.AreEqual (null, file1.ImageTag.Rating);
Assert.AreEqual (0, file2.ImageTag.Rating);
Assert.AreEqual (new DateTime (2009, 8, 9, 19, 12, 44), (DateTime)file1.ImageTag.DateTime);
Expand Down Expand Up @@ -62,8 +62,8 @@ public void TestJPGtoTIFF ()
Assert.AreEqual (TagTypes.TiffIFD | TagTypes.XMP, file2.TagTypes);
Assert.AreEqual ("%test comment%", file1.ImageTag.Comment);
Assert.AreEqual ("%test comment%", file2.ImageTag.Comment);
Assert.AreEqual (new string[] { }, file1.ImageTag.Keywords);
Assert.AreEqual (new string[] { }, file2.ImageTag.Keywords);
Assert.AreEqual (Array.Empty<string> (), file1.ImageTag.Keywords);
Assert.AreEqual (Array.Empty<string> (), file2.ImageTag.Keywords);
Assert.AreEqual (null, file1.ImageTag.Rating);
Assert.AreEqual (null, file2.ImageTag.Rating);
Assert.AreEqual (new DateTime (2009, 8, 9, 19, 12, 44), (DateTime)file1.ImageTag.DateTime);
Expand Down
4 changes: 3 additions & 1 deletion src/TaglibSharp.Tests/Images/GifExiftoolLongCommentTest.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
using System;

using NUnit.Framework;
using TagLib;
using TaglibSharp.Tests.Images.Validators;
Expand All @@ -20,7 +22,7 @@ public void Test ()
true,
new GifExiftoolLongCommentTestInvariantValidator (),
NoModificationValidator.Instance,
new TagKeywordsModificationValidator (new string[] { }, TagTypes.XMP, true),
new TagKeywordsModificationValidator (Array.Empty<string> (), TagTypes.XMP, true),
new CommentModificationValidator (long_comment_orig),
new CommentModificationValidator (long_comment_orig, long_comment_test),
new TagCommentModificationValidator (long_comment_orig, TagTypes.GifComment, true),
Expand Down
4 changes: 3 additions & 1 deletion src/TaglibSharp.Tests/Images/GifExiftoolTangled3Test.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
using System;

using NUnit.Framework;
using TagLib;
using TaglibSharp.Tests.Images.Validators;
Expand All @@ -19,7 +21,7 @@ public void Test ()
true,
new GifExiftoolTangled3TestInvariantValidator (),
NoModificationValidator.Instance,
new TagKeywordsModificationValidator (new string[] { }, TagTypes.XMP, false),
new TagKeywordsModificationValidator (Array.Empty<string> (), TagTypes.XMP, false),
new CommentModificationValidator ("Created with GIMP"),
new TagCommentModificationValidator ("Created with GIMP", TagTypes.GifComment, true),
new RemoveMetadataValidator (TagTypes.GifComment)
Expand Down
4 changes: 3 additions & 1 deletion src/TaglibSharp.Tests/Images/ImageTagTests.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
using System;

using NUnit.Framework;
using TagLib;
using TagLib.Image;
Expand All @@ -20,7 +22,7 @@ public void TestXMPImageTag ()
Assert.IsNotNull (tag);

Assert.AreEqual (null, tag.Comment, "Comment");
Assert.AreEqual (new string[] { }, tag.Keywords, "Keywords");
Assert.AreEqual (Array.Empty<string> (), tag.Keywords, "Keywords");
Assert.AreEqual (0, tag.Rating, "Rating");
Assert.AreEqual (null, tag.DateTime, "DateTime");
Assert.AreEqual (ImageOrientation.None, tag.Orientation, "Orientation");
Expand Down
4 changes: 3 additions & 1 deletion src/TaglibSharp.Tests/Images/JpegNikon1Bibble5Test.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
using System;

using NUnit.Framework;
using TagLib;
using TagLib.IFD;
Expand All @@ -20,7 +22,7 @@ public void Test ()
new CommentModificationValidator (string.Empty),
new TagCommentModificationValidator (null, TagTypes.TiffIFD, true),
new TagCommentModificationValidator (null, TagTypes.XMP, true),
new TagKeywordsModificationValidator (new string[] { }, TagTypes.XMP, true)
new TagKeywordsModificationValidator (Array.Empty<string> (), TagTypes.XMP, true)
);
}
}
Expand Down
4 changes: 3 additions & 1 deletion src/TaglibSharp.Tests/Images/JpegNikon2Bibble5Test.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
using System;

using NUnit.Framework;
using TagLib;
using TagLib.IFD;
Expand All @@ -20,7 +22,7 @@ public void Test ()
new CommentModificationValidator (string.Empty),
new TagCommentModificationValidator (null, TagTypes.TiffIFD, true),
new TagCommentModificationValidator (null, TagTypes.XMP, true),
new TagKeywordsModificationValidator (new string[] { }, TagTypes.XMP, true)
new TagKeywordsModificationValidator (Array.Empty<string> (), TagTypes.XMP, true)
);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/TaglibSharp.Tests/Images/JpegOlympus2Test.cs
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ public void CheckXMP (File file)

Assert.IsNotNull (tag, "tag");

Assert.AreEqual (new string[] { }, tag.Keywords);
Assert.AreEqual (Array.Empty<string> (), tag.Keywords);
Assert.AreEqual ("OLYMPUS CORPORATION", tag.Make);
Assert.AreEqual ("C5060WZ", tag.Model);
Assert.AreEqual ("Adobe Photoshop Elements 4.0", tag.Software);
Expand Down
2 changes: 1 addition & 1 deletion src/TaglibSharp.Tests/Images/PefPentaxKd10Test.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public void ValidateMetadataInvariants (TagLib.Image.File file)
var imagetag = file.ImageTag;
Assert.IsNotNull (imagetag);
Assert.AreEqual (String.Empty, imagetag.Comment, "Comment");
Assert.AreEqual (new string[] { }, imagetag.Keywords, "Keywords");
Assert.AreEqual (Array.Empty<string> (), imagetag.Keywords, "Keywords");
Assert.AreEqual (null, imagetag.Rating, "Rating");
Assert.AreEqual (TagLib.Image.ImageOrientation.LeftBottom, imagetag.Orientation, "Orientation");
Assert.AreEqual ("K10D Ver 1.31 ", imagetag.Software, "Software");
Expand Down
2 changes: 1 addition & 1 deletion src/TaglibSharp.Tests/Images/RawLeicaDigilux2Test.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public void ValidateMetadataInvariants (TagLib.Image.File file)
var imagetag = file.ImageTag;
Assert.IsNotNull (imagetag);
Assert.AreEqual (String.Empty, imagetag.Comment, "Comment");
Assert.AreEqual (new string[] { }, imagetag.Keywords, "Keywords");
Assert.AreEqual (Array.Empty<string> (), imagetag.Keywords, "Keywords");
Assert.AreEqual (null, imagetag.Rating, "Rating");
Assert.AreEqual (TagLib.Image.ImageOrientation.TopLeft, imagetag.Orientation, "Orientation");
Assert.AreEqual (null, imagetag.Software, "Software");
Expand Down
4 changes: 3 additions & 1 deletion src/TaglibSharp.Tests/Images/RecursiveIFDTest.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
using System;

using NUnit.Framework;
using TagLib;
using TagLib.IFD;
Expand Down Expand Up @@ -259,7 +261,7 @@ public void ValidateMetadataInvariants (TagLib.Image.File file)
Assert.IsNotNull (entry, "Entry 0x92D6 missing in IFD 0");
Assert.IsNotNull (entry as UndefinedIFDEntry, "Entry is not an undefined IFD entry!");
var parsed_bytes = (entry as UndefinedIFDEntry).Data.Data;
var bytes = new byte[] { };
var bytes = Array.Empty<byte> ();
Assert.AreEqual (bytes, parsed_bytes);
}
// Thumbnail.0x0103 (Compression/Short/1) "6"
Expand Down
2 changes: 1 addition & 1 deletion src/TaglibSharp.Tests/Images/Rw2PanasonicG1Test.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public void ValidateMetadataInvariants (TagLib.Image.File file)
var imagetag = file.ImageTag;
Assert.IsNotNull (imagetag);
Assert.AreEqual (String.Empty, imagetag.Comment, "Comment");
Assert.AreEqual (new string[] { }, imagetag.Keywords, "Keywords");
Assert.AreEqual (Array.Empty<string> (), imagetag.Keywords, "Keywords");
Assert.AreEqual (null, imagetag.Rating, "Rating");
Assert.AreEqual (TagLib.Image.ImageOrientation.TopLeft, imagetag.Orientation, "Orientation");
Assert.AreEqual (null, imagetag.Software, "Software");
Expand Down
4 changes: 3 additions & 1 deletion src/TaglibSharp.Tests/Images/TiffCanonBibble516BitTest.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
using System;

using NUnit.Framework;
using TagLib;
using TagLib.IFD;
Expand All @@ -20,7 +22,7 @@ public void Test ()
new CommentModificationValidator (string.Empty),
new TagCommentModificationValidator (null, TagTypes.TiffIFD, true),
new TagCommentModificationValidator (null, TagTypes.XMP, true),
new TagKeywordsModificationValidator (new string[] { }, TagTypes.XMP, true)
new TagKeywordsModificationValidator (Array.Empty<string> (), TagTypes.XMP, true)
);
}
}
Expand Down
4 changes: 3 additions & 1 deletion src/TaglibSharp.Tests/Images/TiffCanonBibble58BitTest.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
using System;

using NUnit.Framework;
using TagLib;
using TagLib.IFD;
Expand All @@ -20,7 +22,7 @@ public void Test ()
new CommentModificationValidator (string.Empty),
new TagCommentModificationValidator (null, TagTypes.TiffIFD, true),
new TagCommentModificationValidator (null, TagTypes.XMP, true),
new TagKeywordsModificationValidator (new string[] { }, TagTypes.XMP, true)
new TagKeywordsModificationValidator (Array.Empty<string> (), TagTypes.XMP, true)
);
}
}
Expand Down
4 changes: 3 additions & 1 deletion src/TaglibSharp.Tests/Images/TiffNikon1Bibble516BitTest.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
using System;

using NUnit.Framework;
using TagLib;
using TagLib.IFD;
Expand All @@ -20,7 +22,7 @@ public void Test ()
new CommentModificationValidator (string.Empty),
new TagCommentModificationValidator (null, TagTypes.TiffIFD, true),
new TagCommentModificationValidator (null, TagTypes.XMP, true),
new TagKeywordsModificationValidator (new string[] { }, TagTypes.XMP, true)
new TagKeywordsModificationValidator (Array.Empty<string> (), TagTypes.XMP, true)
);
}
}
Expand Down
4 changes: 3 additions & 1 deletion src/TaglibSharp.Tests/Images/TiffNikon1Bibble58BitTest.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
using System;

using NUnit.Framework;
using TagLib;
using TagLib.IFD;
Expand All @@ -20,7 +22,7 @@ public void Test ()
new CommentModificationValidator (string.Empty),
new TagCommentModificationValidator (null, TagTypes.TiffIFD, true),
new TagCommentModificationValidator (null, TagTypes.XMP, true),
new TagKeywordsModificationValidator (new string[] { }, TagTypes.XMP, true)
new TagKeywordsModificationValidator (Array.Empty<string> (), TagTypes.XMP, true)
);
}
}
Expand Down
4 changes: 3 additions & 1 deletion src/TaglibSharp.Tests/Images/TiffNikon2Bibble516BitTest.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
using System;

using NUnit.Framework;
using TagLib;
using TagLib.IFD;
Expand All @@ -20,7 +22,7 @@ public void Test ()
new CommentModificationValidator (string.Empty),
new TagCommentModificationValidator (null, TagTypes.TiffIFD, true),
new TagCommentModificationValidator (null, TagTypes.XMP, true),
new TagKeywordsModificationValidator (new string[] { }, TagTypes.XMP, true)
new TagKeywordsModificationValidator (Array.Empty<string> (), TagTypes.XMP, true)
);
}
}
Expand Down
4 changes: 3 additions & 1 deletion src/TaglibSharp.Tests/Images/TiffNikon2Bibble58BitTest.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
using System;

using NUnit.Framework;
using TagLib;
using TagLib.IFD;
Expand All @@ -20,7 +22,7 @@ public void Test ()
new CommentModificationValidator (string.Empty),
new TagCommentModificationValidator (null, TagTypes.TiffIFD, true),
new TagCommentModificationValidator (null, TagTypes.XMP, true),
new TagKeywordsModificationValidator (new string[] { }, TagTypes.XMP, true)
new TagKeywordsModificationValidator (Array.Empty<string> (), TagTypes.XMP, true)
);
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
using System;

using NUnit.Framework;
using TagLib;

Expand All @@ -12,7 +14,7 @@ public class KeywordsModificationValidator : IMetadataModificationValidator
readonly string[] orig_keywords;
readonly string[] test_keywords = { "keyword 1", "§$&§%", "99 dsf", "ഈ ヰᛥกツ" };

public KeywordsModificationValidator () : this (new string[] { }) { }
public KeywordsModificationValidator () : this (Array.Empty<string> ()) { }

public KeywordsModificationValidator (string[] orig_keywords)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
using System;

using NUnit.Framework;
using TagLib;

Expand All @@ -12,7 +14,7 @@ public class TagKeywordsModificationValidator : KeywordsModificationValidator
readonly bool tag_present;
readonly TagTypes type;

public TagKeywordsModificationValidator (TagTypes type, bool tag_present) : this (new string[] { }, type, tag_present) { }
public TagKeywordsModificationValidator (TagTypes type, bool tag_present) : this (Array.Empty<string> (), type, tag_present) { }

public TagKeywordsModificationValidator (string[] orig_keywords, TagTypes type, bool tag_present) : base (orig_keywords)
{
Expand Down
12 changes: 7 additions & 5 deletions src/TaglibSharp.Tests/TaggingFormats/ApeTest.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
using System;

using NUnit.Framework;
using TagLib;
using Tag = TagLib.Ape.Tag;
Expand Down Expand Up @@ -61,7 +63,7 @@ public void TestPerformers ()
}
});

tag.Performers = new string[0];
tag.Performers = Array.Empty<string> ();

TagTestWithSave (ref tag, delegate (Tag t, string m) {
Assert.IsTrue (t.IsEmpty, "Value Cleared (IsEmpty): " + m);
Expand Down Expand Up @@ -89,7 +91,7 @@ public void TestAlbumArtists ()
}
});

tag.AlbumArtists = new string[0];
tag.AlbumArtists = Array.Empty<string> ();

TagTestWithSave (ref tag, delegate (Tag t, string m) {
Assert.IsTrue (t.IsEmpty, "Value Cleared (IsEmpty): " + m);
Expand Down Expand Up @@ -117,7 +119,7 @@ public void TestComposers ()
}
});

tag.Composers = new string[0];
tag.Composers = Array.Empty<string> ();

TagTestWithSave (ref tag, delegate (Tag t, string m) {
Assert.IsTrue (t.IsEmpty, "Value Cleared (IsEmpty): " + m);
Expand Down Expand Up @@ -205,7 +207,7 @@ public void TestGenres ()
}
});

tag.Genres = new string[0];
tag.Genres = Array.Empty<string> ();

TagTestWithSave (ref tag, delegate (Tag t, string m) {
Assert.IsTrue (t.IsEmpty, "Value Cleared (IsEmpty): " + m);
Expand Down Expand Up @@ -501,7 +503,7 @@ public void TestPictures ()
}
});

tag.Pictures = new Picture[0];
tag.Pictures = Array.Empty<Picture> ();

TagTestWithSave (ref tag, delegate (Tag t, string m) {
Assert.IsTrue (t.IsEmpty, "Value Cleared (IsEmpty): " + m);
Expand Down
Loading