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

git-svn-id: http://code.djangoproject.com/svn/django/trunk@15175 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Alex Gaynor 2011-01-12 13:39:31 +00:00
parent 29de7ee9cb
commit f544d98896
1 changed files with 6 additions and 7 deletions

View File

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