Skip to content

Commit 0fdba9e

Browse files
authored
Merge pull request #103 from Mungrel/patch-1
Preallocation + const
2 parents f01271d + 5f539c3 commit 0fdba9e

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

main.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -138,11 +138,11 @@ func printVersion(w io.Writer) {
138138

139139
func parse(input string) map[string]string {
140140
lines := strings.Split(string(input), "\n")
141-
pairs := map[string]string{}
141+
pairs := make(map[string]string, len(lines))
142142
for _, line := range lines {
143143
if key, value, ok := strings.Cut(line, "="); ok {
144144
_, exists := pairs[key]
145-
if strings.HasSuffix(key, "[]") && exists {
145+
if exists && strings.HasSuffix(key, "[]") {
146146
pairs[key] += "\n" + value
147147
} else {
148148
pairs[key] = value
@@ -333,7 +333,7 @@ func main() {
333333
}
334334
// "A capability[] directive must precede any value depending on it and these directives should be the first item announced in the protocol." https://git-scm.com/docs/git-credential
335335
fmt.Println("capability[]=authtype")
336-
output := map[string]string{}
336+
output := make(map[string]string, 5)
337337
hostSupportsBearer := host == "bitbucket.org" || host == "codeberg.org" || host == "gitea.com" || looksLikeGitea || strings.HasSuffix(host, ".googlesource.com")
338338
authtypeCapable := strings.Contains(pairs["capability[]"], "authtype")
339339
if bearer && hostSupportsBearer && authtypeCapable {
@@ -414,7 +414,7 @@ func main() {
414414
}
415415
}
416416

417-
var template string = `<!DOCTYPE html>
417+
const template string = `<!DOCTYPE html>
418418
<html lang="en">
419419
<head>
420420
<title>Git authentication</title>

0 commit comments

Comments
 (0)