summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2010-12-20 19:00:36 -0500
committerMike Bayer <mike_mp@zzzcomputing.com>2010-12-20 19:00:36 -0500
commitfafec792aa44be293cd7044f1f12c29e16a4ef8b (patch)
tree193ff00290fe358d01a845f1eb36978d657d15ff /lib/sqlalchemy
parent4ace012030c30e4665fe396f2622fbf09f73ea05 (diff)
downloadsqlalchemy-fafec792aa44be293cd7044f1f12c29e16a4ef8b.tar.gz
callcount reduction
Diffstat (limited to 'lib/sqlalchemy')
-rw-r--r--lib/sqlalchemy/orm/interfaces.py12
-rw-r--r--lib/sqlalchemy/sql/expression.py34
-rw-r--r--lib/sqlalchemy/util/_collections.py7
3 files changed, 30 insertions, 23 deletions
diff --git a/lib/sqlalchemy/orm/interfaces.py b/lib/sqlalchemy/orm/interfaces.py
index 28ab383c3..d50aea83a 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 60ca33b93..b8c06cb08 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 57ce02a1e..4ab52c3d6 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