瀏覽代碼

Merge pull request #455 from abustany/faster-use-detection

query: Improve efficiency of 'USE' statement detection
Chris Bannister 10 年之前
父節點
當前提交
3d916228bd
共有 2 個文件被更改,包括 10 次插入1 次删除
  1. 1 0
      AUTHORS
  2. 9 1
      session.go

+ 1 - 0
AUTHORS

@@ -53,3 +53,4 @@ Matt Heath <matt@mattheath.com>
 Jamie Cuthill <jamie.cuthill@gmail.com>
 Adrian Casajus <adriancasajus@gmail.com>
 John Weldon <johnweldon4@gmail.com>
+Adrien Bustany <adrien@bustany.org>

+ 9 - 1
session.go

@@ -609,10 +609,18 @@ func (q *Query) Exec() error {
 	return iter.err
 }
 
+func isUseStatement(stmt string) bool {
+	if len(stmt) < 3 {
+		return false
+	}
+
+	return strings.ToLower(stmt[0:3]) == "use"
+}
+
 // Iter executes the query and returns an iterator capable of iterating
 // over all results.
 func (q *Query) Iter() *Iter {
-	if strings.Index(strings.ToLower(q.stmt), "use") == 0 {
+	if isUseStatement(q.stmt) {
 		return &Iter{err: ErrUseStmt}
 	}
 	return q.session.executeQuery(q)