Commit 9bca34e
authored
Minor tweaks to pdf Name. (matplotlib#23287)
- 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...1 parent 7858eb4 commit 9bca34e
1 file changed
+4
-7
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
366 | 366 | | |
367 | 367 | | |
368 | 368 | | |
369 | | - | |
| 369 | + | |
| 370 | + | |
370 | 371 | | |
371 | 372 | | |
372 | 373 | | |
373 | 374 | | |
374 | 375 | | |
375 | 376 | | |
376 | 377 | | |
377 | | - | |
| 378 | + | |
378 | 379 | | |
379 | 380 | | |
380 | 381 | | |
381 | 382 | | |
382 | 383 | | |
383 | | - | |
| 384 | + | |
384 | 385 | | |
385 | 386 | | |
386 | 387 | | |
| |||
391 | 392 | | |
392 | 393 | | |
393 | 394 | | |
394 | | - | |
395 | | - | |
396 | | - | |
397 | | - | |
398 | 395 | | |
399 | 396 | | |
400 | 397 | | |
| |||
0 commit comments