]> Cypherpunks repositories - gostls13.git/commitdiff
database/sql: preallocate list slice in Drivers()
authorJulien Schmidt <go@julienschmidt.com>
Mon, 30 Sep 2019 00:07:34 +0000 (00:07 +0000)
committerBrad Fitzpatrick <bradfitz@golang.org>
Mon, 30 Sep 2019 00:45:38 +0000 (00:45 +0000)
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: 2bf575be65e9a449322540270988eaf87cec4245
GitHub-Pull-Request: golang/go#34602
Reviewed-on: https://go-review.googlesource.com/c/go/+/197917
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>

src/database/sql/sql.go

index 93001635bef3b6bb845fe4bf6fb0ce4494d2e5a3..0f5bbc01c9ec933524b03843543a2a74133f179f 100644 (file)
@@ -64,7 +64,7 @@ func unregisterAllDrivers() {
 func Drivers() []string {
        driversMu.RLock()
        defer driversMu.RUnlock()
-       var list []string
+       list := make([]string, 0, len(drivers))
        for name := range drivers {
                list = append(list, name)
        }