From: Mike Bayer Date: Tue, 21 Dec 2010 00:00:36 +0000 (-0500) Subject: callcount reduction X-Git-Tag: rel_0_7b1~132 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=fafec792aa44be293cd7044f1f12c29e16a4ef8b;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git callcount reduction --- diff --git a/lib/sqlalchemy/orm/interfaces.py b/lib/sqlalchemy/orm/interfaces.py index 28ab383c3d..d50aea83a0 100644 --- a/lib/sqlalchemy/orm/interfaces.py +++ b/lib/sqlalchemy/orm/interfaces.py @@ -296,9 +296,9 @@ class StrategizedProperty(MapperProperty): """ def _get_context_strategy(self, context, path): - cls = context.attributes.get(('loaderstrategy', - _reduce_path(path)), None) - if cls: + key = ('loaderstrategy', _reduce_path(path)) + if key in context.attributes: + cls = context.attributes[key] try: return self._strategies[cls] except KeyError: @@ -546,9 +546,9 @@ def _reduce_path(path): """ return tuple([i % 2 != 0 and - path[i] or - getattr(path[i], 'base_mapper', path[i]) - for i in xrange(len(path))]) + element or + getattr(element, 'base_mapper', element) + for i, element in enumerate(path)]) class LoaderStrategy(object): """Describe the loading behavior of a StrategizedProperty object. diff --git a/lib/sqlalchemy/sql/expression.py b/lib/sqlalchemy/sql/expression.py index 60ca33b93e..b8c06cb081 100644 --- a/lib/sqlalchemy/sql/expression.py +++ b/lib/sqlalchemy/sql/expression.py @@ -1090,12 +1090,12 @@ def _clause_element_as_expr(element): return element def _literal_as_column(element): - if hasattr(element, '__clause_element__'): + if isinstance(element, Visitable): + return element + elif hasattr(element, '__clause_element__'): return element.__clause_element__() - elif not isinstance(element, Visitable): - return literal_column(str(element)) else: - return element + return literal_column(str(element)) def _literal_as_binds(element, name=None, type_=None): if hasattr(element, '__clause_element__'): @@ -3557,7 +3557,14 @@ class ColumnClause(_Immutable, ColumnElement): self.table = selectable self.type = sqltypes.to_instance(type_) self.is_literal = is_literal - + + @util.memoized_property + def _from_objects(self): + if self.table is not None: + return [self.table] + else: + return [] + @util.memoized_property def description(self): # Py3K @@ -3601,12 +3608,6 @@ class ColumnClause(_Immutable, ColumnElement): else: return super(ColumnClause, self).label(name) - @property - def _from_objects(self): - if self.table is not None: - return [self.table] - else: - return [] def _bind_param(self, operator, obj): return _BindParamClause(self.name, obj, @@ -3712,6 +3713,9 @@ class TableClause(_Immutable, FromClause): class _SelectBase(Executable, FromClause): """Base class for :class:`Select` and ``CompoundSelects``.""" + _order_by_clause = ClauseList() + _group_by_clause = ClauseList() + def __init__(self, use_labels=False, for_update=False, @@ -3733,9 +3737,11 @@ class _SelectBase(Executable, FromClause): self._limit = limit self._offset = offset self._bind = bind - - self._order_by_clause = ClauseList(*util.to_list(order_by) or []) - self._group_by_clause = ClauseList(*util.to_list(group_by) or []) + + if order_by is not None: + self._order_by_clause = ClauseList(*util.to_list(order_by)) + if group_by is not None: + self._group_by_clause = ClauseList(*util.to_list(group_by)) def as_scalar(self): """return a 'scalar' representation of this selectable, which can be diff --git a/lib/sqlalchemy/util/_collections.py b/lib/sqlalchemy/util/_collections.py index 57ce02a1ea..4ab52c3d6f 100644 --- a/lib/sqlalchemy/util/_collections.py +++ b/lib/sqlalchemy/util/_collections.py @@ -270,9 +270,10 @@ class OrderedSet(set): __str__ = __repr__ def update(self, iterable): - add = self.add - for i in iterable: - add(i) + for e in iterable: + if e not in self: + self._list.append(e) + set.add(self, e) return self __ior__ = update