From 1b024b3e031b7cd5cbb43366eabd48d4c507896b Mon Sep 17 00:00:00 2001 From: James Raspass Date: Fri, 3 Apr 2026 21:37:40 +0100 Subject: [PATCH] Simplify Config.Clone with {maps,slices}.Clone A small change in behaviour in that nil maps and slices will be preserved but if they were fine in the original Config it only makes sense that they'd be fine in the cloned Config. Using std library Clone functions in our Clone function has a nice symmetry. --- connector.go | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/connector.go b/connector.go index 358792b7..01050db0 100644 --- a/connector.go +++ b/connector.go @@ -447,6 +447,7 @@ type Config struct { // awkward to use. set []string `env:"set"` + // Only used in newConfig() and tests; joined in the Multi field at the end. multiHost []string multiHostaddr []netip.Addr multiPort []uint16 @@ -515,11 +516,8 @@ func NewConfig(dsn string) (Config, error) { // Clone returns a copy of the [Config]. func (cfg Config) Clone() Config { - rt := make(map[string]string) - maps.Copy(rt, cfg.Runtime) c := cfg - c.Runtime = rt - c.set = append([]string{}, cfg.set...) + c.Runtime, c.Multi, c.set = maps.Clone(cfg.Runtime), slices.Clone(cfg.Multi), slices.Clone(cfg.set) return c }