From bd95adf4bccda402b13cf43915e6ffef6e7d472c Mon Sep 17 00:00:00 2001 From: Jason Nelson Date: Mon, 1 Apr 2024 22:34:10 -0700 Subject: [PATCH] Optimize RunLengthFilter --- src/UglyToad.PdfPig/Filters/RunLengthFilter.cs | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/UglyToad.PdfPig/Filters/RunLengthFilter.cs b/src/UglyToad.PdfPig/Filters/RunLengthFilter.cs index d2cede37..40b49620 100644 --- a/src/UglyToad.PdfPig/Filters/RunLengthFilter.cs +++ b/src/UglyToad.PdfPig/Filters/RunLengthFilter.cs @@ -55,10 +55,8 @@ var byteToCopy = input[i + 1]; - for (int j = 0; j < numberOfTimesToCopy; j++) - { - output.Write(byteToCopy); - } + output.GetSpan(numberOfTimesToCopy).Slice(0, numberOfTimesToCopy).Fill(byteToCopy); + output.Advance(numberOfTimesToCopy); // Move to the single byte after the byte to copy. i += 2;