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

gh-129813, PEP 782: Use PyBytesWriter in _Py_bytes_maketrans() by vstinner · Pull Request #139044 · python/cpython · GitHub

Repository navigation

Merged
Changes from all commits
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
14 changes: 6 additions & 8 deletions Objects/bytes_methods.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 @@ -356,26 +356,24 @@ The bytes objects frm and to must be of the same length.");
PyObject *
_Py_bytes_maketrans(Py_buffer *frm, Py_buffer *to)
{
PyObject *res = NULL;
Py_ssize_t i;
char *p;

if (frm->len != to->len) {
PyErr_Format(PyExc_ValueError,
"maketrans arguments must have same length");
return NULL;
}
res = PyBytes_FromStringAndSize(NULL, 256);
if (!res)
PyBytesWriter *writer = PyBytesWriter_Create(256);
if (!writer) {
return NULL;
p = PyBytes_AS_STRING(res);
}
char *p = PyBytesWriter_GetData(writer);
Py_ssize_t i;
for (i = 0; i < 256; i++)
p[i] = (char) i;
for (i = 0; i < frm->len; i++) {
p[((unsigned char *)frm->buf)[i]] = ((char *)to->buf)[i];
}

return res;
return PyBytesWriter_Finish(writer);
}

#define FASTSEARCH fastsearch
Expand Down
Loading

Back | FazBrowse Home | New Git URL