From 44e93ba9212f1ded1d70a70f2b4ce1846e149645 Mon Sep 17 00:00:00 2001 From: siddontang Date: Thu, 30 Oct 2014 12:48:52 +0800 Subject: [PATCH] optimize codes --- server/client_resp.go | 3 +-- server/util.go | 11 +++++++++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/server/client_resp.go b/server/client_resp.go index 30a8f87..cfcaf5d 100644 --- a/server/client_resp.go +++ b/server/client_resp.go @@ -12,7 +12,6 @@ import ( "net" "runtime" "strconv" - "strings" "time" ) @@ -124,7 +123,7 @@ func (c *respClient) handleRequest(reqData [][]byte) { c.cmd = "" c.args = reqData[0:0] } else { - c.cmd = strings.ToLower(hack.String(reqData[0])) + c.cmd = hack.String(lowerSlice(reqData[0])) c.args = reqData[1:] } if c.cmd == "quit" { diff --git a/server/util.go b/server/util.go index a243c18..7c5b73d 100644 --- a/server/util.go +++ b/server/util.go @@ -123,3 +123,14 @@ func ReadRequest(in *bufio.Reader, a *arena.Arena) ([][]byte, error) { return req, nil } + +func lowerSlice(buf []byte) []byte { + for i, r := range buf { + if 'A' <= r && r <= 'Z' { + r += 'a' - 'A' + } + + buf[i] = r + } + return buf +}