From cd9f4655ec61bb5f1f1c6c97a656f916c18f9f3e Mon Sep 17 00:00:00 2001 From: Nico Weber Date: Fri, 10 Nov 2023 13:30:37 +0100 Subject: [PATCH] LibPDF: Tweak implementation of postscript `roll` op Since positive offsets roll to the right, it makes more sense to do the big reverse first. Gets rid of an awkward minus sign. No behavior change. --- Userland/Libraries/LibPDF/Function.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Userland/Libraries/LibPDF/Function.cpp b/Userland/Libraries/LibPDF/Function.cpp index 996a892324..4bb00aca1e 100644 --- a/Userland/Libraries/LibPDF/Function.cpp +++ b/Userland/Libraries/LibPDF/Function.cpp @@ -728,7 +728,7 @@ PDFErrorOr PostScriptCalculatorFunction::execute(Vector const& toke TRY(stack.pop()); break; case OperatorType::Roll: { - int j = -(int)TRY(stack.pop()); + int j = (int)TRY(stack.pop()); int n = (int)TRY(stack.pop()); if (n < 0) return Error { Error::Type::RenderingUnsupported, "PostScript roll with negative argument"_string }; @@ -742,9 +742,9 @@ PDFErrorOr PostScriptCalculatorFunction::execute(Vector const& toke return Error { Error::Type::RenderingUnsupported, "PostScript roll with argument larger than stack"_string }; // http://pointer-overloading.blogspot.com/2013/09/algorithms-rotating-one-dimensional.html auto elements = stack.stack.span().slice(stack.top - n, n); + elements.reverse(); elements.slice(0, j).reverse(); elements.slice(j).reverse(); - elements.reverse(); break; } }