8000 Minor tweaks to pdf Name. by anntzer · Pull Request #23287 · matplotlib/matplotlib · GitHub
[go: up one dir, main page]

Skip to content

Minor tweaks to pdf Name. #23287

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

Merged
merged 1 commit into from
Jun 16, 2022
Merged

Minor tweaks to pdf Name. #23287

merged 1 commit into from
Jun 16, 2022

Conversation

anntzer
Copy link
Contributor
@anntzer anntzer commented Jun 16, 2022
  • Fix __str__ for Python3.

    __str__ is never actually used (but can be nice to have for
    debugging purposes); still, str(Name("foo")) currently returns
    /b'foo' where the surrounding b'' is almost certainly a fallout
    from the Py2/Py3 str transition; the intent was to return the same
    thing as pdfRepr, but ascii-decoded. Fix that.

  • Micro-optimize hex escapes.

    In the presence of characters to be escaped, str.translate is quite
    faster than regex.sub:
    $ python -mtimeit -s 'from matplotlib.backends.backend_pdf import Name' 'Name("foo\xff\x01")'
    shows a >2x speedup, for example.
    (There is no difference when no characters are actually subbed. I
    guess the overhead likely comes from the function calls?)
    This is unlikely to matter in reality, but is also shorter and just as
    legible (perhaps even a bit better), so...

PR Summary

PR Checklist

Tests and Styling

  • Has pytest style unit tests (and pytest passes).
  • Is Flake 8 compliant (install flake8-docstrings and run flake8 --docstring-convention=all).

Documentation

  • New features are documented, with examples if plot related.
  • New features have an entry in doc/users/next_whats_new/ (follow instructions in README.rst there).
  • API changes documented in doc/api/next_api_changes/ (follow instructions in README.rst there).
  • Documentation is sphinx and numpydoc compliant (the docs should build without error).

- Fix `__str__` for Python3.

  `__str__` is never actually used (but can be nice to have for
  debugging purposes); still, `str(Name("foo"))` currently returns
  `/b'foo'` where the surrounding `b''` is almost certainly a fallout
  from the Py2/Py3 str transition; the intent was to return the same
  thing as `pdfRepr`, but ascii-decoded.  Fix that.

- Micro-optimize hex escapes.

  In the presence of characters to be escaped, `str.translate` is quite
  faster than `regex.sub`:
  `$ python -mtimeit -s 'from matplotlib.backends.backend_pdf import Name' 'Name("foo\xff\x01")'`
  shows a >2x speedup, for example.
  (There is no difference when no characters are actually subbed.  I
  guess the overhead likely comes from the function calls?)
  This is unlikely to matter in reality, but is also shorter and just as
  legible (perhaps even a bit better), so...
Copy link
Member
@oscargus oscargus left a comment

Choose a reason for hiding this comment

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

Assuming and trusting you that hexify is private enough to not need to be deprecated.

@oscargus oscargus closed this Jun 16, 2022
@oscargus oscargus reopened this Jun 16, 2022
@oscargus oscargus merged commit 9bca34e into matplotlib:main Jun 16, 2022
@oscargus
Copy link
Member

Didn't mean to close...

@anntzer anntzer deleted the pdfname branch June 16, 2022 19:17
oscargus pushed a commit to oscargus/matplotlib that referenced this pull request Jun 18, 2022
- Fix `__str__` for Python3.

  `__str__` is never actually used (but can be nice to have for
  debugging purposes); still, `str(Name("foo"))` currently returns
  `/b'foo'` where the surrounding `b''` is almost certainly a fallout
  from the Py2/Py3 str transition; the intent was to return the same
  thing as `pdfRepr`, but ascii-decoded.  Fix that.

- Micro-optimize hex escapes.

  In the presence of characters to be escaped, `str.translate` is quite
  faster than `regex.sub`:
  `$ python -mtimeit -s 'from matplotlib.backends.backend_pdf import Name' 'Name("foo\xff\x01")'`
  shows a >2x speedup, for example.
  (There is no difference when no characters are actually subbed.  I
  guess the overhead likely comes from the function calls?)
  This is unlikely to matter in reality, but is also shorter and just as
  legible (perhaps even a bit better), so...
@QuLogic QuLogic added this to the v3.6.0 milestone Jun 20, 2022
jklymak pushed a commit to jklymak/matplotlib that referenced this pull request Jun 24, 2022
- Fix `__str__` for Python3.

  `__str__` is never actually used (but can be nice to have for
  debugging purposes); still, `str(Name("foo"))` currently returns
  `/b'foo'` where the surrounding `b''` is almost certainly a fallout
  from the Py2/Py3 str transition; the intent was to return the same
  thing as `pdfRepr`, but ascii-decoded.  Fix that.

- Micro-optimize hex escapes.

  In the presence of characters to be escaped, `str.translate` is quite
  faster than `regex.sub`:
  `$ python -mtimeit -s 'from matplotlib.backends.backend_pdf import Name' 'Name("foo\xff\x01")'`
  shows a >2x speedup, for example.
  (There is no difference when no characters are actually subbed.  I
  guess the overhead likely comes from the function calls?)
  This is unlikely to matter in reality, but is also shorter and just as
  legible (perhaps even a bit better), so...
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.

4 participants
0