Commit d3bb8a34 authored by Chris Toshok's avatar Chris Toshok

split the getattr/setattr of softspace into two try blocks

cpython can be observed setting softspace on an object even if it doesn't start with it.
the getattrInternal in softspace() throws an exception the first time through since the
attribute isn't present.  if we don't turn around and set it on the object, we throw
every time we print, which causes a pretty large perf regression (from ~6 seconds to ~17 seconds.)
parent 533ea58a
......@@ -180,6 +180,7 @@ extern "C" bool softspace(Box* b, bool newval) {
}
bool r;
Box* gotten = NULL;
try {
Box* gotten = getattrInternal(b, "softspace", NULL);
if (!gotten) {
......@@ -187,6 +188,11 @@ extern "C" bool softspace(Box* b, bool newval) {
} else {
r = nonzero(gotten);
}
} catch (ExcInfo e) {
r = 0;
}
try {
setattr(b, "softspace", boxInt(newval));
} catch (ExcInfo e) {
r = 0;
......
# expected: fail
import sys
old_stdout = sys.stdout
class SoftspaceTest(object):
def write(self, str):
print >>old_stdout, self.softspace
old_stdout.write(str)
sys.stdout = SoftspaceTest()
print "hello"
print "world"
print "hello", "world"
print "hello",
print "world",
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment