]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
slight function call reduction
authorMike Bayer <mike_mp@zzzcomputing.com>
Wed, 2 Apr 2008 15:07:06 +0000 (15:07 +0000)
committerMike Bayer <mike_mp@zzzcomputing.com>
Wed, 2 Apr 2008 15:07:06 +0000 (15:07 +0000)
lib/sqlalchemy/sql/compiler.py
test/profiling/compiler.py

index 800881e49a6c1aff6349b95042e6cb3c8efaf953..868904c214e9f54171d6ea2c54e2b336f9808def 100644 (file)
@@ -241,12 +241,15 @@ class DefaultCompiler(engine.Compiled):
 
     def visit_column(self, column, result_map=None, **kwargs):
 
-        if getattr(column, 'table', None) and getattr(column.table, 'schema', None):
-            schema_prefix = self.preparer.quote(column.table, column.table.schema) + '.'
-        else:
-            schema_prefix = ''
-
-        if not column.is_literal:
+        if column._is_oid:
+            name = self.dialect.oid_column_name(column)
+            if name is None:
+                if len(column.table.primary_key) != 0:
+                    pk = list(column.table.primary_key)[0]
+                    return self.visit_column(pk, result_map=result_map, **kwargs)
+                else:
+                    return None
+        elif not column.is_literal:
             name = self._truncated_identifier("colident", column.name)
         else:
             name = column.name
@@ -254,28 +257,19 @@ class DefaultCompiler(engine.Compiled):
         if result_map is not None:
             result_map[name.lower()] = (name, (column, ), column.type)
 
-        if column._is_oid:
-            n = self.dialect.oid_column_name(column)
-            if n is not None:
-                if column.table is None or not column.table.named_with_column:
-                    return n
-                else:
-                    return schema_prefix + self.preparer.quote(column.table, ANONYMOUS_LABEL.sub(self._process_anon, column.table.name)) + "." + n
-            elif len(column.table.primary_key) != 0:
-                pk = list(column.table.primary_key)[0]
-                return self.visit_column(pk, result_map=result_map, **kwargs)
-            else:
-                return None
-        elif column.table is None or not column.table.named_with_column:
-            if getattr(column, "is_literal", False):
-                return self.escape_literal_column(name)
-            else:
-                return self.preparer.quote(column, name)
+        if getattr(column, "is_literal", False):
+            name = self.escape_literal_column(name)
+        else:
+            name = self.preparer.quote(column, name)
+
+        if column.table is None or not column.table.named_with_column:
+            return name
         else:
-            if getattr(column, "is_literal", False):
-                return schema_prefix + self.preparer.quote(column.table, ANONYMOUS_LABEL.sub(self._process_anon, column.table.name)) + "." + self.escape_literal_column(name)
+            if getattr(column.table, 'schema', None):
+                schema_prefix = self.preparer.quote(column.table, column.table.schema) + '.'
             else:
-                return schema_prefix + self.preparer.quote(column.table, ANONYMOUS_LABEL.sub(self._process_anon, column.table.name)) + "." + self.preparer.quote(column, name)
+                schema_prefix = ''
+            return schema_prefix + self.preparer.quote(column.table, ANONYMOUS_LABEL.sub(self._process_anon, column.table.name)) + "." + name
 
     def escape_literal_column(self, text):
         """provide escaping for the literal_column() construct."""
@@ -507,17 +501,19 @@ class DefaultCompiler(engine.Compiled):
         self.stack.append(stack_entry)
 
         # the actual list of columns to print in the SELECT column list.
-        inner_columns = util.OrderedSet()
-
-        for co in select.inner_columns:
-            l = self.label_select_column(select, co, asfrom=asfrom)
-            inner_columns.add(self.process(l, **column_clause_args))
-
-        collist = string.join(inner_columns.difference(util.Set([None])), ', ')
+        inner_columns = util.OrderedSet(
+            [c for c in [
+                self.process(
+                    self.label_select_column(select, co, asfrom=asfrom), 
+                    **column_clause_args) 
+                for co in select.inner_columns
+            ]
+            if c is not None]
+        )
 
         text = " ".join(["SELECT"] + [self.process(x) for x in select._prefixes]) + " "
         text += self.get_select_precolumns(select)
-        text += collist
+        text += ', '.join(inner_columns)
 
         from_strings = []
         for f in froms:
@@ -529,9 +525,8 @@ class DefaultCompiler(engine.Compiled):
         else:
             text += self.default_from()
 
-        whereclause = select._whereclause
-        if whereclause is not None:
-            t = self.process(whereclause)
+        if select._whereclause is not None:
+            t = self.process(select._whereclause)
             if t:
                 text += " \nWHERE " + t
 
index 23e199962ff0161747ffbb4570ba7231f774ab03..41da7e66d06e222d18aae065e751ed8ef11e2ce9 100644 (file)
@@ -23,8 +23,7 @@ class CompileTest(TestBase, AssertsExecutionResults):
     def test_update(self):
         t1.update().compile()
 
-    # TODO: this is alittle high
-    @profiling.function_call_count(130, versions={'2.3': 180, '2.4':140})
+    @profiling.function_call_count(120, versions={'2.3': 180, '2.4':140})
     def test_select(self):
         s = select([t1], t1.c.c2==t2.c.c1)
         s.compile()