Replace fmt.Sprint with strconv.Itoa, specify slice capacity

Uber's Go style guide outlines a slight performance benefit when using
strconv over fmt:
https://github.com/uber-go/guide/blob/dc025303c14891f54d1847396379548773e6123e/style.md#prefer-strconv-over-fmt

Also specifiying slice capacity when it is known beforehand:
https://github.com/uber-go/guide/blob/dc025303c14891f54d1847396379548773e6123e/style.md#specifying-slice-capacity

Signed-off-by: Vartan Benohanian <vartanbeno@gmail.com>
This commit is contained in:
Vartan Benohanian
2020-09-29 13:52:12 -04:00
parent 022cfd5cb1
commit 15ee94fbbe
7 changed files with 15 additions and 8 deletions
+4 -2
View File
@@ -11,6 +11,7 @@ import (
"net/http"
"net/url"
"os"
"strconv"
"strings"
"github.com/google/go-querystring/query"
@@ -63,6 +64,7 @@ func (e *emojis) UnmarshalJSON(data []byte) (err error) {
return
}
*e = make(emojis, 0, len(emojiMap))
for emojiName, emojiValue := range emojiMap {
emoji := new(Emoji)
err = json.Unmarshal(emojiValue, emoji)
@@ -120,8 +122,8 @@ func (s *EmojiService) SetSize(ctx context.Context, subreddit string, height, wi
path := fmt.Sprintf("api/v1/%s/emoji_custom_size", subreddit)
form := url.Values{}
form.Set("height", fmt.Sprint(height))
form.Set("width", fmt.Sprint(width))
form.Set("height", strconv.Itoa(height))
form.Set("width", strconv.Itoa(width))
req, err := s.client.NewRequest(http.MethodPost, path, form)
if err != nil {