summaryrefslogtreecommitdiff
path: root/sqlparse/sql.py
diff options
context:
space:
mode:
authorRyan Wooden <rygwdn@gmail.com>2015-10-21 11:45:05 -0300
committerRyan Wooden <rygwdn@gmail.com>2015-10-21 11:45:05 -0300
commit2bde1b9e494bc8673e0967a7b1f59150131659cc (patch)
tree7d169f4ba71c7d595eb4f3955cf80c3c67513840 /sqlparse/sql.py
parent848973f63de36ff3f90a8b7412dc3ee55fbd95f0 (diff)
downloadsqlparse-2bde1b9e494bc8673e0967a7b1f59150131659cc.tar.gz
Speed up token_index by providing a starting index.
Diffstat (limited to 'sqlparse/sql.py')
-rw-r--r--sqlparse/sql.py10
1 files changed, 9 insertions, 1 deletions
diff --git a/sqlparse/sql.py b/sqlparse/sql.py
index f965f03..7325712 100644
--- a/sqlparse/sql.py
+++ b/sqlparse/sql.py
@@ -343,8 +343,16 @@ class TokenList(Token):
continue
return self.tokens[idx]
- def token_index(self, token):
+ def token_index(self, token, start=0):
"""Return list index of token."""
+ if start > 0:
+ # Performing `index` manually is much faster when starting in the middle
+ # of the list of tokens and expecting to find the token near to the starting
+ # index.
+ for i in xrange(start, len(self.tokens)):
+ if self.tokens[i] == token:
+ return i
+ return -1
return self.tokens.index(token)
def tokens_between(self, start, end, exclude_end=False):