Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add different code-paths to {CMap, ToUnicodeMap}.charCodeOf depending on length, since Array.prototype.indexOf can be extremely inefficient for very large arrays (issue 8372) #8442

Merged
merged 1 commit into from
May 24, 2017

Conversation

Snuffleupagus
Copy link
Collaborator

Fixes #8372.

@Snuffleupagus Snuffleupagus changed the title Add different code-paths to {CMap, ToUnicodeMap}.charCodeOf depending on length, since Array.prototype.indexOf can be very inefficient for extremely large arrays (issue 8372) Add different code-paths to {CMap, ToUnicodeMap}.charCodeOf depending on length, since Array.prototype.indexOf can be extremely inefficient for very large arrays (issue 8372) May 24, 2017
Copy link
Contributor

@yurydelendik yurydelendik left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good

…ng on length, since `Array.prototype.indexOf` can be extremely inefficient for very large arrays (issue 8372)

Fixes 8372.
@Snuffleupagus
Copy link
Collaborator Author

Snuffleupagus commented May 24, 2017

@yurydelendik Thank you for the review!

I realized that I made a stupid mistake: Since for...in stringifies the indices, we need to convert the result back to an integer in order for the method to have consistent return types; please see the interdiff:

diff --git a/src/core/cmap.js b/src/core/cmap.js
index abe2756b..0c9faa4e 100644
--- a/src/core/cmap.js
+++ b/src/core/cmap.js
@@ -307,7 +307,7 @@ var CMap = (function CMapClosure() {
       }
       for (let charCode in map) {
         if (map[charCode] === value) {
-          return charCode;
+          return (charCode | 0);
         }
       }
       return -1;
diff --git a/src/core/fonts.js b/src/core/fonts.js
index 4ed6f90f..3a2d361b 100644
--- a/src/core/fonts.js
+++ b/src/core/fonts.js
@@ -292,7 +292,7 @@ var ToUnicodeMap = (function ToUnicodeMapClosure() {
       }
       for (let charCode in map) {
         if (map[charCode] === value) {
-          return charCode;
+          return (charCode | 0);
         }
       }
       return -1;

@Snuffleupagus
Copy link
Collaborator Author

/botio test

@pdfjsbot
Copy link

From: Bot.io (Windows)


Received

Command cmd_test from @Snuffleupagus received. Current queue size: 0

Live output at: http://54.215.176.217:8877/3b6dbaf4ad9423d/output.txt

@pdfjsbot
Copy link

From: Bot.io (Linux m4)


Received

Command cmd_test from @Snuffleupagus received. Current queue size: 0

Live output at: http://54.67.70.0:8877/48433821fed4bef/output.txt

@pdfjsbot
Copy link

From: Bot.io (Windows)


Success

Full output at http://54.215.176.217:8877/3b6dbaf4ad9423d/output.txt

Total script time: 24.59 mins

  • Font tests: Passed
  • Unit tests: Passed
  • Regression tests: Passed

@pdfjsbot
Copy link

From: Bot.io (Linux m4)


Success

Full output at http://54.67.70.0:8877/48433821fed4bef/output.txt

Total script time: 25.05 mins

  • Font tests: Passed
  • Unit tests: Passed
  • Regression tests: Passed

@Snuffleupagus
Copy link
Collaborator Author

/botio makeref

@pdfjsbot
Copy link

From: Bot.io (Linux m4)


Received

Command cmd_makeref from @Snuffleupagus received. Current queue size: 0

Live output at: http://54.67.70.0:8877/a4dd4d5167c1d0e/output.txt

@pdfjsbot
Copy link

From: Bot.io (Windows)


Received

Command cmd_makeref from @Snuffleupagus received. Current queue size: 0

Live output at: http://54.215.176.217:8877/92e71eefc2c10cc/output.txt

@pdfjsbot
Copy link

From: Bot.io (Linux m4)


Failed

Full output at http://54.67.70.0:8877/a4dd4d5167c1d0e/output.txt

Total script time: 15.07 mins

  • Lint: Passed
  • Make references: FAILED

@pdfjsbot
Copy link

From: Bot.io (Windows)


Success

Full output at http://54.215.176.217:8877/92e71eefc2c10cc/output.txt

Total script time: 23.27 mins

  • Lint: Passed
  • Make references: Passed
  • Check references: Passed

@Snuffleupagus Snuffleupagus merged commit 8d55e6a into mozilla:master May 24, 2017
@Snuffleupagus
Copy link
Collaborator Author

/botio-linux makeref

@pdfjsbot
Copy link

From: Bot.io (Linux m4)


Received

Command cmd_makeref from @Snuffleupagus received. Current queue size: 1

Live output at: http://54.67.70.0:8877/353c0cc35d8c92e/output.txt

@pdfjsbot
Copy link

From: Bot.io (Linux m4)


Failed

Full output at http://54.67.70.0:8877/353c0cc35d8c92e/output.txt

Total script time: 18.29 mins

  • Lint: Passed
  • Make references: FAILED

@Snuffleupagus
Copy link
Collaborator Author

/botio-linux makeref

@pdfjsbot
Copy link

From: Bot.io (Linux m4)


Received

Command cmd_makeref from @Snuffleupagus received. Current queue size: 0

Live output at: http://54.67.70.0:8877/6c495996b723df3/output.txt

@pdfjsbot
Copy link

From: Bot.io (Linux m4)


Failed

Full output at http://54.67.70.0:8877/6c495996b723df3/output.txt

Total script time: 23.01 mins

  • Lint: Passed
  • Make references: FAILED

@Snuffleupagus
Copy link
Collaborator Author

/botio-linux makeref

@pdfjsbot
Copy link

From: Bot.io (Linux m4)


Received

Command cmd_makeref from @Snuffleupagus received. Current queue size: 0

Live output at: http://54.67.70.0:8877/0cc38d0b8835af9/output.txt

@pdfjsbot
Copy link

From: Bot.io (Linux m4)


Success

Full output at http://54.67.70.0:8877/0cc38d0b8835af9/output.txt

Total script time: 23.70 mins

  • Lint: Passed
  • Make references: Passed
  • Check references: Passed

@Snuffleupagus Snuffleupagus deleted the issue-8372 branch May 24, 2017 20:20
movsb pushed a commit to movsb/pdf.js that referenced this pull request Jul 14, 2018
Add different code-paths to `{CMap, ToUnicodeMap}.charCodeOf` depending on length, since `Array.prototype.indexOf` can be extremely inefficient for very large arrays (issue 8372)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants