Skip to content

Commit 061c2a5

Browse files
committed
check stmtCacheSize before acquiring mutex in takeCachedStmt
stmtCacheSize is immutable after connection open, so checking it before the lock avoids mutex overhead when cache is not enabled.
1 parent efa9b1c commit 061c2a5

1 file changed

Lines changed: 2 additions & 2 deletions

File tree

sqlite3.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1906,14 +1906,14 @@ func (c *SQLiteConn) dbConnOpen() bool {
19061906
}
19071907

19081908
func (c *SQLiteConn) takeCachedStmt(query string) *SQLiteStmt {
1909-
if c == nil || query == "" {
1909+
if c == nil || query == "" || c.stmtCacheSize <= 0 {
19101910
return nil
19111911
}
19121912

19131913
c.mu.Lock()
19141914
defer c.mu.Unlock()
19151915

1916-
if c.db == nil || c.stmtCacheSize <= 0 {
1916+
if c.db == nil {
19171917
return nil
19181918
}
19191919
stmts := c.stmtCache[query]

0 commit comments

Comments
 (0)