Skip to content

Commit

Permalink
Update _base.py (#2325)
Browse files Browse the repository at this point in the history
Since b"" is not mutable it causes python to allocate and deallocate memory repeatedly in the for loop which cause hang/long runtime when handle very large string.

For example when using add_js(javascript) to  to add a very big `javascript` bytestring.
  • Loading branch information
zuypt committed Dec 4, 2023
1 parent 40e25ec commit 6cb5343
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion pypdf/generic/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -727,7 +727,7 @@ def readFromStream(


def encode_pdfdocencoding(unicode_string: str) -> bytes:
retval = b""
retval = bytearray()
for c in unicode_string:
try:
retval += b_(chr(_pdfdoc_encoding_rev[c]))
Expand Down

0 comments on commit 6cb5343

Please sign in to comment.