From 5e2cce4853c4e3ffa2ddb0e6a324cd767a4073e7 Mon Sep 17 00:00:00 2001 From: Vladimir Mihailenco Date: Mon, 20 Aug 2012 11:40:27 +0300 Subject: [PATCH] Micro-optimize loop. --- multi.go | 12 +++++------- pipeline.go | 3 ++- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/multi.go b/multi.go index c05d5e1..b620906 100644 --- a/multi.go +++ b/multi.go @@ -82,14 +82,11 @@ func (c *MultiClient) ExecReqs(reqs []Req, conn *Conn) error { statusReq := NewStatusReq() - // Parse MULTI command reply. - _, err = statusReq.ParseReply(conn.Rd) - if err != nil { - return err - } + // Omit last request (EXEC). + reqsLen := len(reqs) - 1 // Parse queued replies. - for i := 1; i < len(reqs)-1; i++ { + for i := 0; i < reqsLen; i++ { _, err = statusReq.ParseReply(conn.Rd) if err != nil { return err @@ -109,7 +106,8 @@ func (c *MultiClient) ExecReqs(reqs []Req, conn *Conn) error { } // Parse replies. - for i := 1; i < len(reqs)-1; i++ { + // Loop starts from 1 to omit first request (MULTI). + for i := 1; i < reqsLen; i++ { req := reqs[i] val, err := req.ParseReply(conn.Rd) if err != nil { diff --git a/pipeline.go b/pipeline.go index 47383c6..d7ed0d1 100644 --- a/pipeline.go +++ b/pipeline.go @@ -67,7 +67,8 @@ func (c *PipelineClient) RunReqs(reqs []Req, conn *Conn) error { return err } - for i := 0; i < len(reqs); i++ { + reqsLen := len(reqs) + for i := 0; i < reqsLen; i++ { req := reqs[i] val, err := req.ParseReply(conn.Rd) if err != nil {