Skip to content

Commit 6734126

Browse files
committed
feat: avoid map alocation
1 parent f321b0a commit 6734126

2 files changed

Lines changed: 5 additions & 1 deletion

File tree

dotenv_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ func TestEnvFileReader(t *testing.T) {
141141
})
142142
}
143143
}
144+
144145
func TestEnvFileReaderUnknownFile(t *testing.T) {
145146
defer func() {
146147
_ = recover()

envconfig.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -327,8 +327,11 @@ func setValue(inp reflect.Value, value string) error {
327327
inp.Set(reflect.Append(inp, elem))
328328
}
329329
case reflect.Map:
330-
mp := reflect.MakeMap(inp.Type())
331330
arr := split(value)
331+
if len(arr) == 0 {
332+
return nil
333+
}
334+
mp := reflect.MakeMap(inp.Type())
332335
for i := 0; i < len(arr); i++ {
333336
kv := strings.SplitN(arr[i], "=", 2)
334337
if len(kv) != 2 {

0 commit comments

Comments
 (0)