From 04b54f03a51f9c102ea07e612268aae86160ef10 Mon Sep 17 00:00:00 2001 From: Karl Seguin Date: Sun, 16 Nov 2014 12:43:47 +0700 Subject: [PATCH] Use LastIndex instead of Split for better performance getting the number of rows affected from CommandTag --- conn.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/conn.go b/conn.go index c0aa36a4..acfb1d16 100644 --- a/conn.go +++ b/conn.go @@ -74,8 +74,12 @@ type CommandTag string // RowsAffected returns the number of rows affected. If the CommandTag was not // for a row affecting command (such as "CREATE TABLE") then it returns 0 func (ct CommandTag) RowsAffected() int64 { - words := strings.Split(string(ct), " ") - n, _ := strconv.ParseInt(words[len(words)-1], 10, 64) + s := string(ct) + index := strings.LastIndex(s, " ") + if index == -1 { + return 0 + } + n, _ := strconv.ParseInt(s[index+1:], 10, 64) return n }