2
0
Эх сурвалжийг харах

small optimization on import types

Joe Shochet 21 жил өмнө
parent
commit
dc22affd43

+ 1 - 1
direct/src/ffi/FFIInterrogateDatabase.py

@@ -51,7 +51,7 @@ def outputGlobalFileImports(file, methodList, CModuleName):
     file.write('# CMODULE [' + CModuleName + ']\n')
     file.write('# CMODULE [' + CModuleName + ']\n')
 
 
     # Import Python's builtin types
     # Import Python's builtin types
-    file.write('import types\n')
+    file.write('from types import IntType, LongType, FloatType, NoneType, StringType\n')
 
 
     # Import the C modules
     # Import the C modules
     CModuleList = []
     CModuleList = []

+ 13 - 13
direct/src/ffi/FFIOverload.py

@@ -59,24 +59,24 @@ def getTypeName(classTypeDesc, typeDesc):
         if ((typeDesc.atomicType == AT_int) or
         if ((typeDesc.atomicType == AT_int) or
             (typeDesc.atomicType == AT_bool) or
             (typeDesc.atomicType == AT_bool) or
             (typeDesc.atomicType == AT_char)):
             (typeDesc.atomicType == AT_char)):
-            return 'types.IntType'
+            return 'IntType'
         
         
         # Floats and doubles are both floats in Python
         # Floats and doubles are both floats in Python
         elif ((typeDesc.atomicType == AT_float) or
         elif ((typeDesc.atomicType == AT_float) or
             (typeDesc.atomicType == AT_double)):
             (typeDesc.atomicType == AT_double)):
-            return 'types.FloatType'
+            return 'FloatType'
 
 
         elif ((typeDesc.atomicType == AT_longlong)):
         elif ((typeDesc.atomicType == AT_longlong)):
-            return 'types.LongType'
+            return 'LongType'
 
 
         # Strings are treated as Python strings
         # Strings are treated as Python strings
         elif ((typeDesc.atomicType == AT_string)):
         elif ((typeDesc.atomicType == AT_string)):
-            return 'types.StringType'
+            return 'StringType'
         
         
         elif (typeDesc.atomicType == AT_void):
         elif (typeDesc.atomicType == AT_void):
             # Convert the void type to None type... I guess...
             # Convert the void type to None type... I guess...
             # So far we do not have any code that uses this
             # So far we do not have any code that uses this
-            return 'types.NoneType'
+            return 'NoneType'
 
 
         else:
         else:
             FFIConstants.notify.error("Unknown atomicType: %s" % (typeDesc.atomicType))
             FFIConstants.notify.error("Unknown atomicType: %s" % (typeDesc.atomicType))
@@ -87,7 +87,7 @@ def getTypeName(classTypeDesc, typeDesc):
     # surrounding class as part of their name
     # surrounding class as part of their name
     # like BoundedObject.__enum__BoundingVolumeType
     # like BoundedObject.__enum__BoundingVolumeType
     elif (typeName.find('__enum__') >= 0):
     elif (typeName.find('__enum__') >= 0):
-        return 'types.IntType'
+        return 'IntType'
 
 
     # If it was not atomic or enum, it must be a class which is a
     # If it was not atomic or enum, it must be a class which is a
     # bit trickier because we output different things depending on the
     # bit trickier because we output different things depending on the
@@ -421,15 +421,15 @@ class FFIMethodArgumentTree:
                     # the object.
                     # the object.
                     condition = '(isinstance(_args[' + `level` + '], ' + typeName + '))'
                     condition = '(isinstance(_args[' + `level` + '], ' + typeName + '))'
                     # Legal types for a float parameter include int and long.
                     # Legal types for a float parameter include int and long.
-                    if (typeName == 'types.FloatType'):
-                        condition += (' or (isinstance(_args[' + `level` + '], types.IntType))')
-                        condition += (' or (isinstance(_args[' + `level` + '], types.LongType))')
+                    if (typeName == 'FloatType'):
+                        condition += (' or (isinstance(_args[' + `level` + '], IntType))')
+                        condition += (' or (isinstance(_args[' + `level` + '], LongType))')
                     # Legal types for a long parameter include int.
                     # Legal types for a long parameter include int.
-                    elif (typeName == 'types.LongType'):
-                        condition += (' or (isinstance(_args[' + `level` + '], types.IntType))')
+                    elif (typeName == 'LongType'):
+                        condition += (' or (isinstance(_args[' + `level` + '], IntType))')
                     # Legal types for an int parameter include long.
                     # Legal types for an int parameter include long.
-                    elif (typeName == 'types.IntType'):
-                        condition += (' or (isinstance(_args[' + `level` + '], types.LongType))')
+                    elif (typeName == 'IntType'):
+                        condition += (' or (isinstance(_args[' + `level` + '], LongType))')
                     
                     
                 indent(file, nesting+2, 'if ' + condition + ':\n')
                 indent(file, nesting+2, 'if ' + condition + ':\n')
                     
                     

+ 3 - 3
direct/src/ffi/FFITypes.py

@@ -631,7 +631,7 @@ class ClassTypeDescriptor(BaseTypeDescriptor):
     def outputBaseImports(self, file):
     def outputBaseImports(self, file):
         indent(file, 0, '# CMODULE [' + self.moduleName + ']\n')
         indent(file, 0, '# CMODULE [' + self.moduleName + ']\n')
         # Everybody imports types for type checking
         # Everybody imports types for type checking
-        indent(file, 0, 'import types\n')
+        indent(file, 0, 'from types import IntType, LongType, FloatType, NoneType, StringType\n')
         indent(file, 0, '\n')
         indent(file, 0, '\n')
 
 
         indent(file, 0, '# Import all the C modules this class uses\n')
         indent(file, 0, '# Import all the C modules this class uses\n')
@@ -757,10 +757,10 @@ class ClassTypeDescriptor(BaseTypeDescriptor):
 
 
         # Store the downcast function modules so the FFIExternalObject
         # Store the downcast function modules so the FFIExternalObject
         # can index into them to find the downcast functions
         # can index into them to find the downcast functions
-        indent(file, nesting+1, '__CModuleDowncasts__ = [')
+        indent(file, nesting+1, '__CModuleDowncasts__ = (')
         for moduleName in self.getCModules():
         for moduleName in self.getCModules():
             file.write(moduleName + 'Downcasts,')
             file.write(moduleName + 'Downcasts,')
-        file.write(']\n')
+        file.write(')\n')
 
 
 
 
     def outputClassFooter(self, file):
     def outputClassFooter(self, file):