summaryrefslogtreecommitdiff
path: root/sqlparse
diff options
context:
space:
mode:
authorRyan Wooden <rygwdn@gmail.com>2015-10-21 07:33:56 -0300
committerRyan Wooden <rygwdn@gmail.com>2015-10-21 07:33:56 -0300
commit848973f63de36ff3f90a8b7412dc3ee55fbd95f0 (patch)
treeacee64acd8a5fa35543a182313567d02bfa86c2f /sqlparse
parent393bed9938826aaf7798dabb1a0187df8f39d72c (diff)
downloadsqlparse-848973f63de36ff3f90a8b7412dc3ee55fbd95f0.tar.gz
Limit number of tokens checked in group_identifier.
This significantly improves performance when grouping a large list of IDs.
Diffstat (limited to 'sqlparse')
-rw-r--r--sqlparse/engine/grouping.py7
-rw-r--r--sqlparse/sql.py4
2 files changed, 7 insertions, 4 deletions
diff --git a/sqlparse/engine/grouping.py b/sqlparse/engine/grouping.py
index a317044..b30e564 100644
--- a/sqlparse/engine/grouping.py
+++ b/sqlparse/engine/grouping.py
@@ -188,9 +188,12 @@ def group_identifier(tlist):
t1 = tl.token_next_by_type(
i, (T.String.Symbol, T.Name, T.Literal.Number.Integer,
T.Literal.Number.Float))
- t2 = tl.token_next_by_instance(i, (sql.Function, sql.Parenthesis))
+
+ i1 = tl.token_index(t1) if t1 else None
+ t2_end = None if i1 is None else i1 + 1
+ t2 = tl.token_next_by_instance(i, (sql.Function, sql.Parenthesis), end=t2_end)
+
if t1 and t2:
- i1 = tl.token_index(t1)
i2 = tl.token_index(t2)
if i1 > i2:
return t2
diff --git a/sqlparse/sql.py b/sqlparse/sql.py
index 5ecfbdc..f965f03 100644
--- a/sqlparse/sql.py
+++ b/sqlparse/sql.py
@@ -256,7 +256,7 @@ class TokenList(Token):
continue
return token
- def token_next_by_instance(self, idx, clss):
+ def token_next_by_instance(self, idx, clss, end=None):
"""Returns the next token matching a class.
*idx* is where to start searching in the list of child tokens.
@@ -267,7 +267,7 @@ class TokenList(Token):
if not isinstance(clss, (list, tuple)):
clss = (clss,)
- for token in self.tokens[idx:]:
+ for token in self.tokens[idx:end]:
if isinstance(token, clss):
return token