Skip to content

Commit 843fec1

Browse files
julienschmidtbradfitz
authored andcommitted
database/sql: preallocate list slice in Drivers()
The required slice capacity is already known. Thus, preallocate a slice with the correct capacity before appending to it. Change-Id: I45ac2c5f1701caeb3dda20451d371713ae7e7365 GitHub-Last-Rev: 2bf575b GitHub-Pull-Request: #34602 Reviewed-on: https://go-review.googlesource.com/c/go/+/197917 Reviewed-by: Brad Fitzpatrick <[email protected]> Run-TryBot: Brad Fitzpatrick <[email protected]> TryBot-Result: Gobot Gobot <[email protected]>
1 parent 9313657 commit 843fec1

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

src/database/sql/sql.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ func unregisterAllDrivers() {
6464
func Drivers() []string {
6565
driversMu.RLock()
6666
defer driversMu.RUnlock()
67-
var list []string
67+
list := make([]string, 0, len(drivers))
6868
for name := range drivers {
6969
list = append(list, name)
7070
}

0 commit comments

Comments
 (0)