From f5e8838bb0292fa6d49f17f6508dd7a9d01b730f Mon Sep 17 00:00:00 2001 From: Nicolas Pierron Date: Thu, 15 Nov 2012 23:46:43 -0800 Subject: [PATCH] Ensure the loop counter is not interpreted as a double. This patch improves pure JavaScript performances by 30% by removing double computations from Type1Parser_extractFontProgram. When parseInt is fed with non numerical values, it returns a NaN which flows into the loop counter which cause every operation to be computed as a double and every index to be trunctated as an int before reading a character. This patch force the NaN value to be coerce as an integer by using a bitwise-or operation with zero. --- src/fonts.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/fonts.js b/src/fonts.js index 646ef5c49..04fcc5dca 100644 --- a/src/fonts.js +++ b/src/fonts.js @@ -4755,7 +4755,9 @@ var Type1Parser = function type1Parser() { i += length; token = ''; } else if (isSeparator(c)) { - length = parseInt(token, 10); + // Use '| 0' to prevent setting a double into length such as the double + // does not flow into the loop variable. + length = parseInt(token, 10) | 0; token = ''; } else { token += c;