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 &lt;<a href="mailto:pit...@free.fr";>pit...@free.fr</a>&gt; 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; &#39;dubious&#39; 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 &amp;&amp; j == len &amp;&amp; PyByteArray_CheckExact(self)) 
{<br>
+        Py_INCREF(self);<br>
+        return (PyObject *)self;<br>
+    }<br>
<br>
bytearray objects are mutable, so you can&#39;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>
&gt; diff -r b5ccdf7c032a Python/bltinmodule.c<br>
&gt; Binary file Python/bltinmodule.c has changed<br>
<br>
Uh, what&#39;s this? bltinmodule.c shouldn&#39;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&#39;t touch that file at 
all. I&#39;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">
&gt; Looking at just how similar these 3 implementations are I feel that we<br>
&gt; could also unify/generalize them into one generic helper implementation<br>
&gt; 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

Reply via email to