Skip to content

Commit fe2ed50

Browse files
zhangyunhao116bradfitz
authored andcommitted
net/url: add upperhex const instead of using string literal
The mime and strconv packages already have a const with this name & value. Change-Id: Ibd7837f854ac8ec3f57943a9d1db07f4cf6db858 GitHub-Last-Rev: 775cdce GitHub-Pull-Request: golang#34389 Reviewed-on: https://go-review.googlesource.com/c/go/+/196437 Reviewed-by: Brad Fitzpatrick <[email protected]>
1 parent e53edaf commit fe2ed50

1 file changed

Lines changed: 4 additions & 2 deletions

File tree

src/net/url/url.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ func (e *Error) Temporary() bool {
4242
return ok && t.Temporary()
4343
}
4444

45+
const upperhex = "0123456789ABCDEF"
46+
4547
func ishex(c byte) bool {
4648
switch {
4749
case '0' <= c && c <= '9':
@@ -324,8 +326,8 @@ func escape(s string, mode encoding) string {
324326
j++
325327
case shouldEscape(c, mode):
326328
t[j] = '%'
327-
t[j+1] = "0123456789ABCDEF"[c>>4]
328-
t[j+2] = "0123456789ABCDEF"[c&15]
329+
t[j+1] = upperhex[c>>4]
330+
t[j+2] = upperhex[c&15]
329331
j += 3
330332
default:
331333
t[j] = s[i]

0 commit comments

Comments
 (0)