You've already forked goreleaser
							
							
				mirror of
				https://github.com/goreleaser/goreleaser.git
				synced 2025-10-30 23:58:09 +02:00 
			
		
		
		
	refactor: optimize strings replacers (#4788)
Reuse strings replace instead of recreation
This commit is contained in:
		| @@ -19,15 +19,17 @@ func Notice(ctx *context.Context, property string) { | ||||
| 	NoticeCustom(ctx, property, "{{ .Property }} should not be used anymore, check {{ .URL }} for more info") | ||||
| } | ||||
|  | ||||
| var urlPropertyReplacer = strings.NewReplacer( | ||||
| 	".", "", | ||||
| 	"_", "", | ||||
| 	":", "", | ||||
| 	" ", "-", | ||||
| ) | ||||
|  | ||||
| // NoticeCustom warns the user about the deprecation of the given property. | ||||
| func NoticeCustom(ctx *context.Context, property, tmpl string) { | ||||
| 	// replaces . and _ with - | ||||
| 	url := baseURL + strings.NewReplacer( | ||||
| 		".", "", | ||||
| 		"_", "", | ||||
| 		":", "", | ||||
| 		" ", "-", | ||||
| 	).Replace(property) | ||||
| 	url := baseURL + urlPropertyReplacer.Replace(property) | ||||
| 	var out bytes.Buffer | ||||
| 	if err := template. | ||||
| 		Must(template.New("deprecation").Parse("DEPRECATED: "+tmpl)). | ||||
|   | ||||
| @@ -167,6 +167,12 @@ func isSupportedArchlinuxArch(arch, arm string) bool { | ||||
| 	return false | ||||
| } | ||||
|  | ||||
| var termuxArchReplacer = strings.NewReplacer( | ||||
| 	"386", "i686", | ||||
| 	"amd64", "x86_64", | ||||
| 	"arm64", "aarch64", | ||||
| ) | ||||
|  | ||||
| func create(ctx *context.Context, fpm config.NFPM, format string, artifacts []*artifact.Artifact) error { | ||||
| 	// TODO: improve mips handling on nfpm | ||||
| 	infoArch := artifacts[0].Goarch + artifacts[0].Goarm + artifacts[0].Gomips // key used for the ConventionalFileName et al | ||||
| @@ -193,13 +199,8 @@ func create(ctx *context.Context, fpm config.NFPM, format string, artifacts []*a | ||||
| 			return nil | ||||
| 		} | ||||
|  | ||||
| 		replacer := strings.NewReplacer( | ||||
| 			"386", "i686", | ||||
| 			"amd64", "x86_64", | ||||
| 			"arm64", "aarch64", | ||||
| 		) | ||||
| 		infoArch = replacer.Replace(infoArch) | ||||
| 		arch = replacer.Replace(arch) | ||||
| 		infoArch = termuxArchReplacer.Replace(infoArch) | ||||
| 		arch = termuxArchReplacer.Replace(arch) | ||||
| 		fpm.Bindir = termuxPrefixedDir(fpm.Bindir) | ||||
| 		fpm.Libdirs.Header = termuxPrefixedDir(fpm.Libdirs.Header) | ||||
| 		fpm.Libdirs.CArchive = termuxPrefixedDir(fpm.Libdirs.CArchive) | ||||
|   | ||||
| @@ -343,27 +343,29 @@ func filter(reverse bool) func(content, exp string) string { | ||||
| 	} | ||||
| } | ||||
|  | ||||
| var mdv2EscapeReplacer = strings.NewReplacer( | ||||
| 	"_", "\\_", | ||||
| 	"*", "\\*", | ||||
| 	"[", "\\[", | ||||
| 	"]", "\\]", | ||||
| 	"(", "\\(", | ||||
| 	")", "\\)", | ||||
| 	"~", "\\~", | ||||
| 	"`", "\\`", | ||||
| 	">", "\\>", | ||||
| 	"#", "\\#", | ||||
| 	"+", "\\+", | ||||
| 	"-", "\\-", | ||||
| 	"=", "\\=", | ||||
| 	"|", "\\|", | ||||
| 	"{", "\\{", | ||||
| 	"}", "\\}", | ||||
| 	".", "\\.", | ||||
| 	"!", "\\!", | ||||
| ) | ||||
|  | ||||
| func mdv2Escape(s string) string { | ||||
| 	return strings.NewReplacer( | ||||
| 		"_", "\\_", | ||||
| 		"*", "\\*", | ||||
| 		"[", "\\[", | ||||
| 		"]", "\\]", | ||||
| 		"(", "\\(", | ||||
| 		")", "\\)", | ||||
| 		"~", "\\~", | ||||
| 		"`", "\\`", | ||||
| 		">", "\\>", | ||||
| 		"#", "\\#", | ||||
| 		"+", "\\+", | ||||
| 		"-", "\\-", | ||||
| 		"=", "\\=", | ||||
| 		"|", "\\|", | ||||
| 		"{", "\\{", | ||||
| 		"}", "\\}", | ||||
| 		".", "\\.", | ||||
| 		"!", "\\!", | ||||
| 	).Replace(s) | ||||
| 	return mdv2EscapeReplacer.Replace(s) | ||||
| } | ||||
|  | ||||
| func makemap(kvs ...string) (map[string]string, error) { | ||||
|   | ||||
		Reference in New Issue
	
	Block a user