@@ -173,17 +173,14 @@ PyObject *CPyBytes_RjustDefaultFill(PyObject *self, CPyTagged width) {
173
173
Py_ssize_t width_size_t = CPyTagged_AsSsize_t (width );
174
174
Py_ssize_t len = PyBytes_Size (self );
175
175
if (width_size_t <= len ) {
176
- return PyBytes_FromStringAndSize (PyBytes_AsString (self ), len );
176
+ Py_INCREF (self );
177
+ return self ;
177
178
}
178
- // should this be a constant?
179
- PyObject * fillbyte = PyBytes_FromStringAndSize (" " , 1 );
180
- // can we optimize out the above line and the below line?
181
- char fill = PyBytes_AsString (fillbyte )[0 ];
182
179
Py_ssize_t pad = width_size_t - len ;
183
180
PyObject * result = PyBytes_FromStringAndSize (NULL , width_size_t );
184
181
if (!result ) return NULL ;
185
182
char * res_buf = PyBytes_AsString (result );
186
- memset (res_buf , fill , pad );
183
+ memset (res_buf , ' ' , pad );
187
184
memcpy (res_buf + pad , PyBytes_AsString (self ), len );
188
185
return result ;
189
186
}
@@ -201,7 +198,8 @@ PyObject *CPyBytes_RjustCustomFill(PyObject *self, CPyTagged width, PyObject *fi
201
198
Py_ssize_t width_size_t = CPyTagged_AsSsize_t (width );
202
199
Py_ssize_t len = PyBytes_Size (self );
203
200
if (width_size_t <= len ) {
204
- return PyBytes_FromStringAndSize (PyBytes_AsString (self ), len );
201
+ Py_INCREF (self );
202
+ return self ;
205
203
}
206
204
char fill = PyBytes_AsString (fillbyte )[0 ];
207
205
Py_ssize_t pad = width_size_t - len ;
@@ -222,18 +220,15 @@ PyObject *CPyBytes_LjustDefaultFill(PyObject *self, CPyTagged width) {
222
220
Py_ssize_t width_size_t = CPyTagged_AsSsize_t (width );
223
221
Py_ssize_t len = PyBytes_Size (self );
224
222
if (width_size_t <= len ) {
225
- return PyBytes_FromStringAndSize (PyBytes_AsString (self ), len );
223
+ Py_INCREF (self );
224
+ return self ;
226
225
}
227
- // should this be a constant?
228
- PyObject * fillbyte = PyBytes_FromStringAndSize (" " , 1 );
229
- // can we optimize out the above line and the below line?
230
- char fill = PyBytes_AsString (fillbyte )[0 ];
231
226
Py_ssize_t pad = width_size_t - len ;
232
227
PyObject * result = PyBytes_FromStringAndSize (NULL , width_size_t );
233
228
if (!result ) return NULL ;
234
229
char * res_buf = PyBytes_AsString (result );
235
230
memcpy (res_buf , PyBytes_AsString (self ), len );
236
- memset (res_buf + len , fill , pad );
231
+ memset (res_buf + len , ' ' , pad );
237
232
return result ;
238
233
}
239
234
@@ -250,7 +245,8 @@ PyObject *CPyBytes_LjustCustomFill(PyObject *self, CPyTagged width, PyObject *fi
250
245
Py_ssize_t width_size_t = CPyTagged_AsSsize_t (width );
251
246
Py_ssize_t len = PyBytes_Size (self );
252
247
if (width_size_t <= len ) {
253
- return PyBytes_FromStringAndSize (PyBytes_AsString (self ), len );
248
+ Py_INCREF (self );
249
+ return self ;
254
250
}
255
251
char fill = PyBytes_AsString (fillbyte )[0 ];
256
252
Py_ssize_t pad = width_size_t - len ;
0 commit comments