Skip to content

Commit 3ee6d56

Browse files
authored
Merge pull request #413 from drewnoakes/cleanup
Small perf fixes and some code reuse
2 parents 1882a43 + aa6f6dc commit 3ee6d56

File tree

4 files changed

+14
-21
lines changed

4 files changed

+14
-21
lines changed

MetadataExtractor/Formats/Jpeg/JpegSegmentType.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ public static bool CanContainMetadata(this JpegSegmentType type)
222222

223223
/// <summary>Gets JPEG segment types that might contain metadata.</summary>
224224
#if NET5_0_OR_GREATER
225-
public static IReadOnlyList<JpegSegmentType> CanContainMetadataTypes { get; } = Enum.GetValues<JpegSegmentType>().Cast<JpegSegmentType>().Where(type => type.CanContainMetadata()).ToList();
225+
public static IReadOnlyList<JpegSegmentType> CanContainMetadataTypes { get; } = Enum.GetValues<JpegSegmentType>().Where(type => type.CanContainMetadata()).ToList();
226226
#else
227227
public static IReadOnlyList<JpegSegmentType> CanContainMetadataTypes { get; } = Enum.GetValues(typeof(JpegSegmentType)).Cast<JpegSegmentType>().Where(type => type.CanContainMetadata()).ToList();
228228
#endif

MetadataExtractor/Formats/QuickTime/QuickTimeMetadataReader.cs

+3-2
Original file line numberDiff line numberDiff line change
@@ -263,8 +263,9 @@ void MoovHandler(AtomCallbackArgs a)
263263
case "uuid":
264264
{
265265
ReadOnlySpan<byte> cr3 = [0x85, 0xc0, 0xb6, 0x87, 0x82, 0x0f, 0x11, 0xe0, 0x81, 0x11, 0xf4, 0xce, 0x46, 0x2b, 0x6a, 0x48];
266-
var uuid = a.Reader.GetBytes(cr3.Length);
267-
if (cr3.SequenceEqual(uuid))
266+
Span<byte> actual = stackalloc byte[cr3.Length];
267+
a.Reader.GetBytes(actual);
268+
if (cr3.SequenceEqual(actual))
268269
{
269270
QuickTimeReader.ProcessAtoms(stream, UuidHandler, a.BytesLeft);
270271
}

MetadataExtractor/Formats/QuickTime/QuickTimeReader.cs

+3-13
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
// Copyright (c) Drew Noakes and contributors. All Rights Reserved. Licensed under the Apache License, Version 2.0. See LICENSE in the project root for license information.
22

3+
using MetadataExtractor.Formats.Iso14496;
4+
35
namespace MetadataExtractor.Formats.QuickTime
46
{
57
/// <summary>
@@ -43,19 +45,7 @@ public sealed class AtomCallbackArgs(uint type, long size, Stream stream, long s
4345
/// <summary>
4446
/// Gets the string representation of this atom's type.
4547
/// </summary>
46-
public string TypeString
47-
{
48-
get
49-
{
50-
var bytes = BitConverter.GetBytes(Type);
51-
Array.Reverse(bytes);
52-
#if NETSTANDARD1_3
53-
return Encoding.UTF8.GetString(bytes);
54-
#else
55-
return Encoding.ASCII.GetString(bytes);
56-
#endif
57-
}
58-
}
48+
public string TypeString => TypeStringConverter.ToTypeString(Type);
5949

6050
/// <summary>
6151
/// Computes the number of bytes remaining in the atom, given the <see cref="Stream"/> position.

MetadataExtractor/Formats/QuickTime/QuickTimeReaderExtensions.cs

+7-5
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,17 @@ public static string Get4ccString(this SequentialReader reader)
1616
// https://en.wikipedia.org/wiki/FourCC
1717

1818
Span<byte> bytes = stackalloc byte[4];
19-
Span<char> chars = stackalloc char[4];
2019

2120
reader.GetBytes(bytes);
2221

2322
// NOTE we cannot just use Encoding.ASCII here, as that can replace certain non-printable characters with '?'
24-
chars[0] = (char)bytes[0];
25-
chars[1] = (char)bytes[1];
26-
chars[2] = (char)bytes[2];
27-
chars[3] = (char)bytes[3];
23+
Span<char> chars =
24+
[
25+
(char)bytes[0],
26+
(char)bytes[1],
27+
(char)bytes[2],
28+
(char)bytes[3]
29+
];
2830

2931
#if NET462 || NETSTANDARD1_3
3032
fixed (char* pChars = chars)

0 commit comments

Comments
 (0)