Author: Maciej Fijalkowski <[email protected]>
Branch:
Changeset: r1170:60a2d2c57ca6
Date: 2013-02-25 19:19 +0200
http://bitbucket.org/cffi/cffi/changeset/60a2d2c57ca6/
Log: Merged in alex_gaynor/cffi/library-module (pull request #9)
Make the library be a ModuleType subclass so that on PyPy it is
optimized for the fact that the attribtues are generally never re-
assigned.
diff --git a/cffi/vengine_gen.py b/cffi/vengine_gen.py
--- a/cffi/vengine_gen.py
+++ b/cffi/vengine_gen.py
@@ -1,4 +1,6 @@
-import sys, os, binascii, imp, shutil
+import sys
+import types
+
from . import model, ffiplatform
@@ -54,12 +56,15 @@
# call loading_gen_struct() to get the struct layout inferred by
# the C compiler
self._load(module, 'loading')
- #
- # build the FFILibrary class and instance
- class FFILibrary(object):
+
+ # build the FFILibrary class and instance, this is a module subclass
+ # because modules are expected to have usually-constant-attributes and
+ # in PyPy this means the JIT is able to treat attributes as constant,
+ # which we want.
+ class FFILibrary(types.ModuleType):
_cffi_generic_module = module
_cffi_ffi = self.ffi
- library = FFILibrary()
+ library = FFILibrary("")
#
# finally, call the loaded_gen_xxx() functions. This will set
# up the 'library' object.
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit