From 8b9baa680aa9e194f0e8f23ae9484927986a9f60 Mon Sep 17 00:00:00 2001 From: Alexey Kostin Date: Mon, 14 May 2018 00:40:36 +0300 Subject: [PATCH] Faster ASCIIconvert --- bt2qbt.go | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/bt2qbt.go b/bt2qbt.go index d2b64b3..5836c58 100644 --- a/bt2qbt.go +++ b/bt2qbt.go @@ -19,17 +19,19 @@ import ( "strings" "sync" "time" + "bytes" ) -func ASCIIconvert(s string) (newstring string) { +func ASCIIconvert(s string) string { + var buffer bytes.Buffer for _, c := range s { if c > 127 { - newstring = fmt.Sprintf("%v\\x%x", newstring, c) + buffer.WriteString(`\x` + strconv.FormatUint(uint64(c), 16)) } else { - newstring = fmt.Sprintf("%v%v", newstring, string(c)) + buffer.WriteString(string(c)) } } - return + return buffer.String() } func checknotexists(s string, tags []string) (bool, string) {