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

Small improvements in CFFCompiler.encodeNumber and CFFCompiler.encodeFloat #12002

Merged
merged 2 commits into from
Jun 15, 2020

Conversation

Snuffleupagus
Copy link
Collaborator

  • Simplify the "is integer" checks in CFFCompiler.encodeNumber

    The isNaN check is obviously redundant, since NaN is the only value that isn't equal to itself; see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/NaN#Examples

    The parseFloat/parseInt comparison would make sense if the value ever contains a String, which however is never actually the case. Besides looking through the code, I've also run the entire test-suite locally with assert(typeof value === "number", "encodeNumber"); added at the top of the method and there were no failures.

    Hence we can simplify the "is integer" check a bit in the CFFCompiler.encodeNumber method.

  • Lazily initialize, and cache, the regular expression used in CFFCompiler.encodeFloat

    There's no particular reason for re-creating the regular expression over and over for every encodeFloat invocation, as far as I can tell.

The `isNaN` check is obviously redundant, since `NaN` is the only value that isn't equal to itself; see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/NaN#Examples

The `parseFloat`/`parseInt` comparison would make sense if the `value` ever contains a String, which however is never actually the case. Besides looking through the code, I've also run the entire test-suite locally with `assert(typeof value === "number", "encodeNumber");` added at the top of the method and there were no failures.

Hence we can simplify the "is integer" check a bit in the `CFFCompiler.encodeNumber` method.
…iler.encodeFloat`

There's no particular reason for re-creating the regular expression over and over for every `encodeFloat` invocation, as far as I can tell.
@Snuffleupagus Snuffleupagus changed the title Small improvements in CFFCompiler.encodeNumber and CFFCompiler.encodeNumber Small improvements in CFFCompiler.encodeNumber and CFFCompiler.encodeFloat Jun 15, 2020
@Snuffleupagus
Copy link
Collaborator Author

/botio test

@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/7699c6950420367/output.txt

@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/e91986e8f817c17/output.txt

@pdfjsbot
Copy link

From: Bot.io (Linux m4)


Failed

Full output at http://54.67.70.0:8877/7699c6950420367/output.txt

Total script time: 25.59 mins

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

Image differences available at: http://54.67.70.0:8877/7699c6950420367/reftest-analyzer.html#web=eq.log

@pdfjsbot
Copy link

From: Bot.io (Windows)


Failed

Full output at http://54.215.176.217:8877/e91986e8f817c17/output.txt

Total script time: 28.88 mins

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

Image differences available at: http://54.215.176.217:8877/e91986e8f817c17/reftest-analyzer.html#web=eq.log

@timvandermeij timvandermeij merged commit 6bb64da into mozilla:master Jun 15, 2020
@timvandermeij
Copy link
Contributor

Good find!

@Snuffleupagus Snuffleupagus deleted the cff-encodeNumber branch June 16, 2020 07:59
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