diff --git a/src/UglyToad.PdfPig.Core/IndirectReference.cs b/src/UglyToad.PdfPig.Core/IndirectReference.cs index c742280d8..f7f38b598 100644 --- a/src/UglyToad.PdfPig.Core/IndirectReference.cs +++ b/src/UglyToad.PdfPig.Core/IndirectReference.cs @@ -6,7 +6,7 @@ /// /// Used to uniquely identify and refer to objects in the PDF file. /// - public readonly struct IndirectReference + public readonly struct IndirectReference : IEquatable { /// /// A positive integer object number. @@ -31,15 +31,15 @@ public IndirectReference(long objectNumber, int generation) } /// - public override bool Equals(object obj) + public bool Equals(IndirectReference other) { - if (obj is IndirectReference reference) - { - return reference.ObjectNumber == ObjectNumber - && reference.Generation == Generation; - } + return other.ObjectNumber == ObjectNumber && other.Generation == Generation; + } - return false; + /// + public override bool Equals(object obj) + { + return obj is IndirectReference other && Equals(other); } /// diff --git a/src/UglyToad.PdfPig/CrossReference/CrossReferenceTable.cs b/src/UglyToad.PdfPig/CrossReference/CrossReferenceTable.cs index fe404ea2c..91be7106c 100644 --- a/src/UglyToad.PdfPig/CrossReference/CrossReferenceTable.cs +++ b/src/UglyToad.PdfPig/CrossReference/CrossReferenceTable.cs @@ -49,7 +49,7 @@ internal CrossReferenceTable(CrossReferenceType type, IReadOnlyDictionary(); + var result = new Dictionary(capacity: objectOffsets.Count); foreach (var objectOffset in objectOffsets) { result[objectOffset.Key] = objectOffset.Value; diff --git a/src/UglyToad.PdfPig/Parser/FileStructure/CrossReferenceObjectOffsetValidator.cs b/src/UglyToad.PdfPig/Parser/FileStructure/CrossReferenceObjectOffsetValidator.cs index 54eea31d0..8d8b6f256 100644 --- a/src/UglyToad.PdfPig/Parser/FileStructure/CrossReferenceObjectOffsetValidator.cs +++ b/src/UglyToad.PdfPig/Parser/FileStructure/CrossReferenceObjectOffsetValidator.cs @@ -24,11 +24,11 @@ public static bool ValidateCrossReferenceOffsets(IInputBytes bytes, CrossReferen return true; } - var builderOffsets = new Dictionary(); - var bruteForceOffsets = BruteForceSearcher.GetObjectLocations(bytes); if (bruteForceOffsets.Count > 0) { + var builderOffsets = new Dictionary(); + // find all object streams foreach (var entry in crossReferenceTable.ObjectOffsets) { @@ -39,11 +39,11 @@ public static bool ValidateCrossReferenceOffsets(IInputBytes bytes, CrossReferen // TODO: more validation of streams. builderOffsets[entry.Key] = entry.Value; } + } - foreach (var item in bruteForceOffsets) - { - builderOffsets[item.Key] = item.Value; - } + foreach (var item in bruteForceOffsets) + { + builderOffsets[item.Key] = item.Value; } actualOffsets = builderOffsets;