Author ezio.melotti
Recipients Arfrever, ezio.melotti, pitrou, serhiy.storchaka
Date 2012-09-22.08:00:22
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1348300825.22.0.104973677648.issue15958@psf.upfronthosting.co.za>
In-reply-to
Content
Attached patch adds support for memoryviews to bytes.join:

>>> b''.join([memoryview(b'foo'), b'bar'])
b'foobar'

The implementation currently has some duplication, because it does a first pass to calculate the total size to allocate, and another pass to create the result that calculates the individual sizes again.  Py_SIZE(item) can't be used here for memoryviews, so during the first pass it's now necessary to check for memoryviews and extract the len from the memoryview buffer, and then do it again during the second pass.
If necessary this could be optimized/improved.

I also tried to check for multi-dimensional and non-contiguous buffers, but I didn't manage to obtain a failure so I removed the check for now.
More tests should probably be added to cover these cases, and possibly the patch should be adjusted accordingly.

If/when the patch is OK I'll do the same for bytearrays.
History
Date User Action Args
2012-09-22 08:00:25ezio.melottisetrecipients: + ezio.melotti, pitrou, Arfrever, serhiy.storchaka
2012-09-22 08:00:25ezio.melottisetmessageid: <1348300825.22.0.104973677648.issue15958@psf.upfronthosting.co.za>
2012-09-22 08:00:24ezio.melottilinkissue15958 messages
2012-09-22 08:00:23ezio.melotticreate