Author: Armin Rigo <[email protected]>
Branch:
Changeset: r79468:af9d90e513b9
Date: 2015-09-05 16:00 +0200
http://bitbucket.org/pypy/pypy/changeset/af9d90e513b9/
Log: Sort the vtable fields by decreasing size, like we do for the
instance fields.
diff --git a/rpython/rtyper/rclass.py b/rpython/rtyper/rclass.py
--- a/rpython/rtyper/rclass.py
+++ b/rpython/rtyper/rclass.py
@@ -251,9 +251,7 @@
allmethods = {}
# class attributes
llfields = []
- attrs = self.classdef.attrs.items()
- attrs.sort()
- for name, attrdef in attrs:
+ for name, attrdef in self.classdef.attrs.items():
if attrdef.readonly:
s_value = attrdef.s_value
s_unboundmethod = self.prepare_method(s_value)
@@ -271,6 +269,8 @@
mangled_name = mangle('pbc%d' % counter, attr)
pbcfields[access_set, attr] = mangled_name, r
llfields.append((mangled_name, r.lowleveltype))
+ llfields.sort()
+ llfields.sort(key=attr_reverse_size)
#
self.rbase = getclassrepr(self.rtyper, self.classdef.basedef)
self.rbase.setup()
@@ -492,19 +492,7 @@
fields[name] = mangled_name, r
myllfields.append((mangled_name, r.lowleveltype))
- # Sort the instance attributes by decreasing "likely size",
- # as reported by rffi.sizeof(), to minimize padding holes in C.
- # Fields of the same size are sorted by name (by attrs.sort()
- # above) just to minimize randomness.
- def keysize((_, T)):
- if T is lltype.Void:
- return None
- from rpython.rtyper.lltypesystem.rffi import sizeof
- try:
- return -sizeof(T)
- except StandardError:
- return None
- myllfields.sort(key=keysize)
+ myllfields.sort(key=attr_reverse_size)
if llfields is None:
llfields = myllfields
else:
@@ -1072,6 +1060,19 @@
(lltype.typeOf(widest), name))
return default
+def attr_reverse_size((_, T)):
+ # This is used to sort the instance or class attributes by decreasing
+ # "likely size", as reported by rffi.sizeof(), to minimize padding
+ # holes in C. Fields should first be sorted by name, just to minimize
+ # randomness, and then (stably) sorted by 'attr_reverse_size'.
+ if T is lltype.Void:
+ return None
+ from rpython.rtyper.lltypesystem.rffi import sizeof
+ try:
+ return -sizeof(T)
+ except StandardError:
+ return None
+
# ____________________________________________________________
#
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit