Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 8 additions & 13 deletions pgconn/pgconn.go
Original file line number Diff line number Diff line change
Expand Up @@ -777,25 +777,20 @@ func NewCommandTag(s string) CommandTag {
// RowsAffected returns the number of rows affected. If the CommandTag was not
// for a row affecting command (e.g. "CREATE TABLE") then it returns 0.
func (ct CommandTag) RowsAffected() int64 {
// Find last non-digit
idx := -1
// Parse the number from the end in a single pass.
var n int64
var mult int64 = 1

for i := len(ct.s) - 1; i >= 0; i-- {
if ct.s[i] >= '0' && ct.s[i] <= '9' {
idx = i
c := ct.s[i]
if c >= '0' && c <= '9' {
n += int64(c-'0') * mult
mult *= 10
} else {
break
}
}

if idx == -1 {
return 0
}

var n int64
for _, b := range ct.s[idx:] {
n = n*10 + int64(b-'0')
}

return n
}

Expand Down
Loading