This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author pitrou
Recipients benjamin.peterson, ezio.melotti, jcon, pitrou, vstinner
Date 2011-08-24.13:32:11
SpamBayes Score 5.0612033e-07
Marked as misclassified No
Message-id <1314192733.43.0.923458063158.issue12807@psf.upfronthosting.co.za>
In-reply-to
Content
+    if (len == 0) {
+        if (PyByteArray_CheckExact(self)) {
+            Py_INCREF(self);
+            return (PyObject *)self;
+        }
+        return PyByteArray_FromStringAndSize(NULL, 0);
+    }

This looks like a dubious micro-optimization. If len == 0,
all loops will exit early anyway (same for similar snippets in bytesobject.c and unicodeobject.c).

+    if (i == 0 && j == len && PyByteArray_CheckExact(self)) {
+        Py_INCREF(self);
+        return (PyObject *)self;
+    }

bytearray objects are mutable, so you can't return the same object without breaking expected semantics. e.g.:

>>> a = bytearray()
>>> b = a.strip()
>>> b.append(49)
>>> a
bytearray(b'')
>>> b
bytearray(b'1')

> diff -r b5ccdf7c032a Python/bltinmodule.c
> Binary file Python/bltinmodule.c has changed

Uh, what's this? bltinmodule.c shouldn't be considered a binary file.
It probably means you added a NUL byte in it by mistake.

> Looking at just how similar these 3 implementations are I feel that we 
> could also unify/generalize them into one generic helper implementation 
> and leave the object marshaling up to the type specific methods.

You could put it in Objects/stringlib.
History
Date User Action Args
2011-08-24 13:32:13pitrousetrecipients: + pitrou, vstinner, benjamin.peterson, ezio.melotti, jcon
2011-08-24 13:32:13pitrousetmessageid: <1314192733.43.0.923458063158.issue12807@psf.upfronthosting.co.za>
2011-08-24 13:32:12pitroulinkissue12807 messages
2011-08-24 13:32:11pitroucreate