diff --git a/src/UglyToad.PdfPig/IO/ByteArrayInputBytes.cs b/src/UglyToad.PdfPig/IO/ByteArrayInputBytes.cs
index 69b1c7fc..15fcd83c 100644
--- a/src/UglyToad.PdfPig/IO/ByteArrayInputBytes.cs
+++ b/src/UglyToad.PdfPig/IO/ByteArrayInputBytes.cs
@@ -7,6 +7,7 @@
internal class ByteArrayInputBytes : IInputBytes
{
+ private readonly int upperBound;
private readonly byte[] bytes;
[DebuggerStepThrough]
@@ -26,6 +27,8 @@
this.bytes = bytes.ToArray();
}
+ upperBound = this.bytes.Length - 1;
+
currentOffset = -1;
}
@@ -34,20 +37,21 @@
{
this.bytes = bytes ?? throw new ArgumentNullException(nameof(bytes));
currentOffset = -1;
+ upperBound = bytes.Length - 1;
}
- private long currentOffset;
+ private int currentOffset;
public long CurrentOffset => currentOffset + 1;
public bool MoveNext()
{
- if (currentOffset == bytes.Length - 1)
+ if (currentOffset == upperBound)
{
return false;
}
currentOffset++;
- CurrentByte = bytes[(int)currentOffset];
+ CurrentByte = bytes[currentOffset];
return true;
}
@@ -57,23 +61,23 @@
public byte? Peek()
{
- if (currentOffset == bytes.Length - 1)
+ if (currentOffset == upperBound)
{
return null;
}
- return bytes[(int)currentOffset + 1];
+ return bytes[currentOffset + 1];
}
public bool IsAtEnd()
{
- return currentOffset == bytes.Length - 1;
+ return currentOffset == upperBound;
}
public void Seek(long position)
{
currentOffset = (int)position - 1;
- CurrentByte = currentOffset < 0 ? (byte)0 : bytes[(int)currentOffset];
+ CurrentByte = currentOffset < 0 ? (byte)0 : bytes[currentOffset];
}
public int Read(byte[] buffer, int? length = null)
@@ -100,8 +104,8 @@
}
var viableLength = (bytes.Length - currentOffset - 1);
- var readLength = (int)(viableLength < bytesToRead ? viableLength : bytesToRead);
- var startFrom = (int)currentOffset + 1;
+ var readLength = viableLength < bytesToRead ? viableLength : bytesToRead;
+ var startFrom = currentOffset + 1;
Array.Copy(bytes, startFrom, buffer, 0, readLength);
diff --git a/src/UglyToad.PdfPig/Parser/Parts/ReadHelper.cs b/src/UglyToad.PdfPig/Parser/Parts/ReadHelper.cs
index 372fab9d..244b05a6 100644
--- a/src/UglyToad.PdfPig/Parser/Parts/ReadHelper.cs
+++ b/src/UglyToad.PdfPig/Parser/Parts/ReadHelper.cs
@@ -110,10 +110,9 @@
///
/// These values are specified in table 1 (page 12) of ISO 32000-1:2008.
///
- public static bool IsWhitespace(int c)
+ public static bool IsWhitespace(byte c)
{
- return c == 0 || c == 9 || c == 12 || c == AsciiLineFeed
- || c == AsciiCarriageReturn || c == ' ';
+ return c == 0 || c == 32 || c == AsciiLineFeed || c == AsciiCarriageReturn || c == 9 || c == 12;
}
public static bool IsEndOfLine(char c) => IsEndOfLine((byte) c);
diff --git a/src/UglyToad.PdfPig/Tokens/NumericToken.cs b/src/UglyToad.PdfPig/Tokens/NumericToken.cs
index beb6ded7..69861714 100644
--- a/src/UglyToad.PdfPig/Tokens/NumericToken.cs
+++ b/src/UglyToad.PdfPig/Tokens/NumericToken.cs
@@ -1,8 +1,8 @@
namespace UglyToad.PdfPig.Tokens
{
- using System;
using System.Globalization;
+ ///
///
/// PDF supports integer and real numbers. Integer objects represent mathematical integers within a certain interval centered at 0.
/// Real objects approximate mathematical real numbers, but with limited range and precision.
@@ -16,22 +16,17 @@
///
/// Whether the number represented has a non-zero decimal part.
///
- public bool HasDecimalPlaces { get; }
+ public bool HasDecimalPlaces => decimal.Floor(Data) != Data;
///
/// The value of this number as an .
///
- public int Int { get; }
-
- ///
- /// Whether the number overflows an integer.
- ///
- public bool IsBiggerThanInt { get; }
-
+ public int Int => (int) Data;
+
///
/// The value of this number as a .
///
- public long Long { get; }
+ public long Long => (long) Data;
///
/// The value of this number as a .
@@ -45,17 +40,6 @@
public NumericToken(decimal value)
{
Data = value;
- HasDecimalPlaces = decimal.Floor(value) != value;
- Long = (long) value;
-
- try
- {
- Int = (int) value;
- }
- catch (OverflowException)
- {
- IsBiggerThanInt = true;
- }
}
///