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.
This commit is contained in:
Yasuhiro Matsumoto
2026-04-08 13:38:45 +09:00
parent efa9b1c75d
commit 061c2a5f43

View File

@@ -1906,14 +1906,14 @@ func (c *SQLiteConn) dbConnOpen() bool {
}
func (c *SQLiteConn) takeCachedStmt(query string) *SQLiteStmt {
if c == nil || query == "" {
if c == nil || query == "" || c.stmtCacheSize <= 0 {
return nil
}
c.mu.Lock()
defer c.mu.Unlock()
if c.db == nil || c.stmtCacheSize <= 0 {
if c.db == nil {
return nil
}
stmts := c.stmtCache[query]