Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit ea032f3

Browse filesBrowse files
authored
Merge pull request #899 from hcraM41/master
code opt: performance optimization
2 parents 3067968 + bd12b8a commit ea032f3
Copy full SHA for ea032f3

File tree

Expand file treeCollapse file tree

2 files changed

+10
-8
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+10
-8
lines changed

โ€Žclient/client.go

Copy file name to clipboardExpand all lines: client/client.go
+8-5Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package client
22

33
import (
44
"bufio"
5-
"bytes"
65
"context"
76
"crypto/tls"
87
"errors"
@@ -11,6 +10,7 @@ import (
1110
"net"
1211
"net/url"
1312
"strconv"
13+
"strings"
1414
"sync"
1515
"time"
1616

@@ -495,15 +495,18 @@ func urlencode(data map[string]string) string {
495495
if len(data) == 0 {
496496
return ""
497497
}
498-
var buf bytes.Buffer
498+
var buf strings.Builder
499+
first := true
499500
for k, v := range data {
501+
if !first {
502+
buf.WriteByte('&')
503+
}
500504
buf.WriteString(url.QueryEscape(k))
501505
buf.WriteByte('=')
502506
buf.WriteString(url.QueryEscape(v))
503-
buf.WriteByte('&')
507+
first = false
504508
}
505-
s := buf.String()
506-
return s[0 : len(s)-1]
509+
return buf.String()
507510
}
508511

509512
func (client *Client) send(ctx context.Context, call *Call) {

โ€Žreflection/server_reflection.go

Copy file name to clipboardExpand all lines: reflection/server_reflection.go
+2-3Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package reflection
22

33
import (
4-
"bytes"
54
"context"
65
"encoding/json"
76
"fmt"
@@ -52,7 +51,7 @@ type (s *{{$name}}) {{.Name}}(ctx context.Context, arg *{{.ReqName}}, reply *{{.
5251

5352
func (si ServiceInfo) String() string {
5453
tpl := template.Must(template.New("service").Parse(siTemplate))
55-
var buf bytes.Buffer
54+
var buf strings.Builder
5655
_ = tpl.Execute(&buf, si)
5756
return buf.String()
5857
}
@@ -160,7 +159,7 @@ func (r *Reflection) GetService(ctx context.Context, s string, reply *string) er
160159
}
161160

162161
func (r *Reflection) GetServices(ctx context.Context, s string, reply *string) error {
163-
var buf bytes.Buffer
162+
var buf strings.Builder
164163

165164
pkg := `package `
166165

0 commit comments

Comments
0ย (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.