From ddd7d1af203d6d260c970d8ee8749fedbce6bba1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Anssi=20K=C3=A4=C3=A4ri=C3=A4inen?= Date: Sun, 30 Sep 2012 17:50:56 +0300 Subject: [PATCH] Avoided storing ExpressionNodes in dicts --- django/db/models/sql/expressions.py | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/django/db/models/sql/expressions.py b/django/db/models/sql/expressions.py index ac8fea6da3..374509914d 100644 --- a/django/db/models/sql/expressions.py +++ b/django/db/models/sql/expressions.py @@ -6,7 +6,7 @@ class SQLEvaluator(object): def __init__(self, expression, query, allow_joins=True): self.expression = expression self.opts = query.get_meta() - self.cols = {} + self.cols = [] self.contains_aggregate = False self.expression.prepare(self, query, allow_joins) @@ -18,11 +18,15 @@ class SQLEvaluator(object): return self.expression.evaluate(self, qn, connection) def relabel_aliases(self, change_map): - for node, col in self.cols.items(): + new_cols = [] + for node, col in self.cols: if hasattr(col, "relabel_aliases"): col.relabel_aliases(change_map) + new_cols.append((node, col)) else: - self.cols[node] = (change_map.get(col[0], col[0]), col[1]) + new_cols.append((node, + (change_map.get(col[0], col[0]), col[1]))) + self.cols = new_cols ##################################################### # Vistor methods for initial expression preparation # @@ -41,7 +45,7 @@ class SQLEvaluator(object): if (len(field_list) == 1 and node.name in query.aggregate_select.keys()): self.contains_aggregate = True - self.cols[node] = query.aggregate_select[node.name] + self.cols.append((node, query.aggregate_select[node.name])) else: try: field, source, opts, join_list, last, _ = query.setup_joins( @@ -49,7 +53,7 @@ class SQLEvaluator(object): query.get_initial_alias(), False) col, _, join_list = query.trim_joins(source, join_list, last, False) - self.cols[node] = (join_list[-1], col) + self.cols.append((node, (join_list[-1], col))) except FieldDoesNotExist: raise FieldError("Cannot resolve keyword %r into field. " "Choices are: %s" % (self.name, @@ -80,7 +84,13 @@ class SQLEvaluator(object): return connection.ops.combine_expression(node.connector, expressions), expression_params def evaluate_leaf(self, node, qn, connection): - col = self.cols[node] + col = None + for n, c in self.cols: + if n is node: + col = c + break + if col is None: + raise ValueError("Given node not found") if hasattr(col, 'as_sql'): return col.as_sql(qn, connection), () else: