FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

gh-101178: refactor base64.b85encode to be memory friendly by romuald · Pull Request #112248 · python/cpython · GitHub

Repository navigation

Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension .c  (1) All 1 file type selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
Prev Previous commit
Credit to git's implementation and more comments
  • Loading branch information
romuald committed Feb 17, 2025
commit 2fc892cd05efbbaff2e0c4a171cdda155e26720a
5 changes: 4 additions & 1 deletion Modules/binascii.c
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -1290,8 +1290,9 @@ binascii__b2a_base85_impl(PyObject *module, Py_buffer *data,
size_t i = 0 ;
int padding = 0;

// Conversion largely inspired from git base85 implementation
while (i < bin_len) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

I would also credit the git implementation for this one as it's heavily based on it.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Credit added. I don't know if I should phrase it differently?

I've also added some other comments to try to explain the logic more

// translate each 4 byte chunk to 32bit integer
// Translate each 4 byte chunk to 32bit integer
uint32_t value = 0;
for (int cnt = 24; cnt >= 0; cnt -= 8) {
value |= bin_data[i] << cnt;
Expand All @@ -1302,6 +1303,7 @@ binascii__b2a_base85_impl(PyObject *module, Py_buffer *data,
}
}

// Handle NULL only and space-only cases (specific to ASCII85)
if (foldnuls && value == 0) {
*ascii_data++ = 'z';
}
Expand All @@ -1317,6 +1319,7 @@ binascii__b2a_base85_impl(PyObject *module, Py_buffer *data,
}
Comment thread
romuald marked this conversation as resolved.
}

// Expand the last folded null in case it did not fill a full chunk
if (padding && !pad && foldnuls && ascii_data[-1] == 'z') {
ascii_data--;
memset(ascii_data, table[0], 5);
Expand Down

Back | FazBrowse Home | New Git URL