From 47cbc06ef6f528e4d30a869ec533d010ee79b064 Mon Sep 17 00:00:00 2001 From: thestig Date: Wed, 12 Oct 2016 09:37:28 -0700 Subject: Optimize roll operator in CPDF_PSEngine. Rolling 0 times is a no-op. Rolling 0 items is a no-op. Rolling N items J times is the same as rolling N items J % N times. This also avoids an integer overflow corner case. BUG=chromium:648077 Review-Url: https://codereview.chromium.org/2412833002 --- core/fpdfapi/page/fpdf_page_func.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/core/fpdfapi/page/fpdf_page_func.cpp b/core/fpdfapi/page/fpdf_page_func.cpp index bf44a1e7c5..6af787ea49 100644 --- a/core/fpdfapi/page/fpdf_page_func.cpp +++ b/core/fpdfapi/page/fpdf_page_func.cpp @@ -376,10 +376,12 @@ FX_BOOL CPDF_PSEngine::DoOperator(PDF_PSOP op) { case PSOP_ROLL: { int j = static_cast(Pop()); int n = static_cast(Pop()); - if (m_StackCount == 0) + if (j == 0 || n == 0 || m_StackCount == 0) break; if (n < 0 || n > static_cast(m_StackCount)) break; + + j %= n; if (j < 0) { for (int i = 0; i < -j; i++) { FX_FLOAT first = m_Stack[m_StackCount - n]; -- cgit v1.2.3