Author: Alex
Date: 2011-01-12 07:39:31 -0600 (Wed, 12 Jan 2011)
New Revision: 15175

Modified:
   django/trunk/django/db/backends/__init__.py
Log:
2 small optimizations: a) move an import out of a function, b) remove a cache 
that did nothing, tiny tiny speed up on CPython, but a big one on PyPy

Modified: django/trunk/django/db/backends/__init__.py
===================================================================
--- django/trunk/django/db/backends/__init__.py 2011-01-11 01:03:08 UTC (rev 
15174)
+++ django/trunk/django/db/backends/__init__.py 2011-01-12 13:39:31 UTC (rev 
15175)
@@ -1,11 +1,13 @@
 import decimal
 from threading import local
 
+from django.conf import settings
 from django.db import DEFAULT_DB_ALIAS
 from django.db.backends import util
 from django.utils import datetime_safe
 from django.utils.importlib import import_module
 
+
 class BaseDatabaseWrapper(local):
     """
     Represents a database connection.
@@ -73,7 +75,6 @@
             self.connection = None
 
     def cursor(self):
-        from django.conf import settings
         cursor = self._cursor()
         if (self.use_debug_cursor or
             (self.use_debug_cursor is None and settings.DEBUG)):
@@ -205,7 +206,7 @@
     compiler_module = "django.db.models.sql.compiler"
 
     def __init__(self):
-        self._cache = {}
+        self._cache = None
 
     def autoinc_sql(self, table, column):
         """
@@ -388,11 +389,9 @@
         in the namespace corresponding to the `compiler_module` attribute
         on this backend.
         """
-        if compiler_name not in self._cache:
-            self._cache[compiler_name] = getattr(
-                import_module(self.compiler_module), compiler_name
-            )
-        return self._cache[compiler_name]
+        if self._cache is None:
+            self._cache = import_module(self.compiler_module)
+        return getattr(self._cache, compiler_name)
 
     def quote_name(self, name):
         """

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en.

Reply via email to