From bbee09da308fcc95634a14cde496092b5c676f46 Mon Sep 17 00:00:00 2001 From: Martin Kobetic Date: Tue, 24 Jun 2014 14:43:21 +0000 Subject: copy receiver stats in Stats.Sub() --- db.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/db.go b/db.go index 6ec07a7..1cfa10f 100644 --- a/db.go +++ b/db.go @@ -575,7 +575,8 @@ type Stats struct { // This is useful when obtaining stats at two different points and time and // you need the performance counters that occurred within that time span. func (s *Stats) Sub(other *Stats) Stats { - var diff Stats + var diff Stats = *s + diff.TxN = other.TxN - s.TxN diff.TxStats = s.TxStats.Sub(&other.TxStats) return diff } -- cgit v1.2.3 From 32e22b3bb6a5f03977e38513b44b33d3cc1d94e5 Mon Sep 17 00:00:00 2001 From: Martin Kobetic Date: Tue, 24 Jun 2014 15:30:28 +0000 Subject: add some guards for nil pointers --- db.go | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/db.go b/db.go index 1cfa10f..a37f687 100644 --- a/db.go +++ b/db.go @@ -575,8 +575,15 @@ type Stats struct { // This is useful when obtaining stats at two different points and time and // you need the performance counters that occurred within that time span. func (s *Stats) Sub(other *Stats) Stats { - var diff Stats = *s - diff.TxN = other.TxN - s.TxN + var diff Stats + if s == nil { + return diff + } + diff = *s + if other == nil { + return diff + } + diff.TxN = other.TxN - diff.TxN diff.TxStats = s.TxStats.Sub(&other.TxStats) return diff } -- cgit v1.2.3 From 8dd18bd620ab676d8bba00813f5b85267bf7e00e Mon Sep 17 00:00:00 2001 From: Martin Kobetic Date: Tue, 24 Jun 2014 17:19:50 +0000 Subject: review tweaks --- db.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/db.go b/db.go index a37f687..d15dc74 100644 --- a/db.go +++ b/db.go @@ -577,7 +577,11 @@ type Stats struct { func (s *Stats) Sub(other *Stats) Stats { var diff Stats if s == nil { - return diff + if other == nil { + return diff + } else { + return *other + } } diff = *s if other == nil { -- cgit v1.2.3