From: Mike Bayer Date: Fri, 7 Nov 2008 17:08:23 +0000 (+0000) Subject: avoid some often unnecessary method calls. i think we might have squeezed all we... X-Git-Tag: rel_0_5rc3~4 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=17b758faed4dfdc7973d0c0b861ece40de10b101;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git avoid some often unnecessary method calls. i think we might have squeezed all we're going to squeeze out of compiler at this point. --- diff --git a/lib/sqlalchemy/sql/compiler.py b/lib/sqlalchemy/sql/compiler.py index 1c7c66f477..851bc30ac6 100644 --- a/lib/sqlalchemy/sql/compiler.py +++ b/lib/sqlalchemy/sql/compiler.py @@ -459,7 +459,8 @@ class DefaultCompiler(engine.Compiled): column.table is not None and \ not isinstance(column.table, sql.Select): return _CompileLabel(column, sql._generated_label(column.name)) - elif not isinstance(column, (sql._UnaryExpression, sql._TextClause, sql._BindParamClause)) and (not hasattr(column, 'name') or isinstance(column, sql._Function)): + elif not isinstance(column, (sql._UnaryExpression, sql._TextClause, sql._BindParamClause)) \ + and (not hasattr(column, 'name') or isinstance(column, sql._Function)): return _CompileLabel(column, column.anon_label) else: return column @@ -479,13 +480,13 @@ class DefaultCompiler(engine.Compiled): # if existingfroms: # correlate_froms = correlate_froms.union(existingfroms) + self.stack.append({'from':correlate_froms, 'iswrapper':iswrapper}) + if compound_index==1 and not entry or entry.get('iswrapper', False): column_clause_args = {'result_map':self.result_map} else: column_clause_args = {} - self.stack.append({'from':correlate_froms, 'iswrapper':iswrapper}) - # the actual list of columns to print in the SELECT column list. inner_columns = util.unique_list( c for c in [ @@ -515,18 +516,22 @@ class DefaultCompiler(engine.Compiled): if t: text += " \nWHERE " + t - group_by = self.process(select._group_by_clause) - if group_by: - text += " GROUP BY " + group_by + if select._group_by_clause.clauses: + group_by = self.process(select._group_by_clause) + if group_by: + text += " GROUP BY " + group_by if select._having is not None: t = self.process(select._having) if t: text += " \nHAVING " + t - text += self.order_by_clause(select) - text += (select._limit is not None or select._offset is not None) and self.limit_clause(select) or "" - text += self.for_update_clause(select) + if select._order_by_clause.clauses: + text += self.order_by_clause(select) + if select._limit is not None or select._offset is not None: + text += self.limit_clause(select) + if select.for_update: + text += self.for_update_clause(select) self.stack.pop(-1) diff --git a/test/profiling/compiler.py b/test/profiling/compiler.py index 5be8c0f8e2..2f1cbad596 100644 --- a/test/profiling/compiler.py +++ b/test/profiling/compiler.py @@ -23,7 +23,7 @@ class CompileTest(TestBase, AssertsExecutionResults): def test_update(self): t1.update().compile() - @profiling.function_call_count(195, versions={'2.4':133}) + @profiling.function_call_count(185, versions={'2.4':133}) def test_select(self): s = select([t1], t1.c.c2==t2.c.c1) s.compile() diff --git a/test/profiling/zoomark_orm.py b/test/profiling/zoomark_orm.py index 3fff96e1ab..8350fbab4c 100644 --- a/test/profiling/zoomark_orm.py +++ b/test/profiling/zoomark_orm.py @@ -310,7 +310,7 @@ class ZooMarkTest(TestBase): def test_profile_5_aggregates(self): self.test_baseline_5_aggregates() - @profiling.function_call_count(3752) + @profiling.function_call_count(3545) def test_profile_6_editing(self): self.test_baseline_6_editing()