John O'Connor <tehj...@gmail.com> added the comment:
You are right about those lines in particular; 'dubious' as you say.
Though, the point overall was that the general implementation was noticeably
faster (regardless of those smaller changes).
However, I do think that the single check for len == 0 saves time
particularly
from do_xstrip where we call _getbuffer().
I see. I must have been trigger happy.
> > 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.
>
> I didn't touch that file at all. I'm not sure what that is. :-P
> 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.
>
I figured. I will when I am able to get to it.
- John
----------
Added file: http://bugs.python.org/file23040/unnamed
_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue12807>
_______________________________________
<div><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0
0 .8ex;border-left:1px #ccc solid;padding-left:1ex;"><br>
Antoine Pitrou <<a href="mailto:pit...@free.fr">pit...@free.fr</a>> added
the comment:<br>
<br>
+ Â Â if (len == 0) {<br>
+ Â Â Â Â if (PyByteArray_CheckExact(self)) {<br>
+ Â Â Â Â Â Â Py_INCREF(self);<br>
+ Â Â Â Â Â Â return (PyObject *)self;<br>
+ Â Â Â Â }<br>
+ Â Â Â Â return PyByteArray_FromStringAndSize(NULL, 0);<br>
+ Â Â }<br>
<br>
This looks like a dubious micro-optimization. If len == 0,<br>
all loops will exit early anyway (same for similar snippets in bytesobject.c
and unicodeobject.c).<br>
<br></blockquote><br class="Apple-interchange-newline">You are right about
those lines in particular; 'dubious' as you say. <div>Though, the
point overall was that the general implementation was noticeably</div><div>
faster (regardless of those smaller
changes). </div><div><br></div><div>However, I do think that the single
check for len == 0 saves time particularly</div><div>from do_xstrip where we
call _getbuffer().</div><div><br></div>
<div><br></div><blockquote class="gmail_quote" style="margin:0 0 0
.8ex;border-left:1px #ccc solid;padding-left:1ex;">
+ Â Â if (i == 0 && j == len && PyByteArray_CheckExact(self))
{<br>
+ Â Â Â Â Py_INCREF(self);<br>
+ Â Â Â Â return (PyObject *)self;<br>
+ Â Â }<br>
<br>
bytearray objects are mutable, so you can't return the same object without
breaking expected semantics. e.g.:<br>
<br></blockquote><div><br></div><div>I see. I must have been trigger
happy.</div><div><br></div><blockquote class="gmail_quote" style="margin:0 0 0
.8ex;border-left:1px #ccc solid;padding-left:1ex;"><br>
> diff -r b5ccdf7c032a Python/bltinmodule.c<br>
> Binary file Python/bltinmodule.c has changed<br>
<br>
Uh, what's this? bltinmodule.c shouldn't be considered a binary
file.<br>
It probably means you added a NUL byte in it by mistake.<br>
<div class="im"><br></div></blockquote><div>I didn't touch that file at
all. I'm not sure what that is. :-P</div><div><br></div><blockquote
class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc
solid;padding-left:1ex;">
<div class="im">
> Looking at just how similar these 3 implementations are I feel that we<br>
> could also unify/generalize them into one generic helper implementation<br>
> and leave the object marshaling up to the type specific methods.<br>
<br>
</div>You could put it in
Objects/stringlib.<br></blockquote><div><br></div><div>I figured. I will when I
am able to get to it.</div><div><br></div><div><br></div><div>-
John</div></div></div>
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com