Skip to content

Commit 59f84fa

Browse files
committed
counts.go: return early in the "unusual" cases
1 parent 669067d commit 59f84fa

File tree

1 file changed

+16
-16
lines changed

1 file changed

+16
-16
lines changed

counts/counts.go

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -40,23 +40,23 @@ func (n1 *Count32) Increment(n2 Count32) {
4040
// AdjustMaxIfNecessary adjusts `*n1` to be `max(*n1, n2)`. Return
4141
// true iff `n2` was greater than `*n1`.
4242
func (n1 *Count32) AdjustMaxIfNecessary(n2 Count32) bool {
43-
if n2 > *n1 {
44-
*n1 = n2
45-
return true
46-
} else {
43+
if n2 <= *n1 {
4744
return false
4845
}
46+
47+
*n1 = n2
48+
return true
4949
}
5050

5151
// AdjustMaxIfPossible adjusts `*n1` to be `max(*n1, n2)`. Return true
5252
// iff `n2` was greater than or equal to `*n1`.
5353
func (n1 *Count32) AdjustMaxIfPossible(n2 Count32) bool {
54-
if n2 >= *n1 {
55-
*n1 = n2
56-
return true
57-
} else {
54+
if n2 < *n1 {
5855
return false
5956
}
57+
58+
*n1 = n2
59+
return true
6060
}
6161

6262
// Count64 is a count of something, capped at math.MaxUint64.
@@ -91,21 +91,21 @@ func (n1 *Count64) Increment(n2 Count64) {
9191
// AdjustMaxIfNecessary adjusts `*n1` to be `max(*n1, n2)`. Return
9292
// true iff `n2` was greater than `*n1`.
9393
func (n1 *Count64) AdjustMaxIfNecessary(n2 Count64) bool {
94-
if n2 > *n1 {
95-
*n1 = n2
96-
return true
97-
} else {
94+
if n2 <= *n1 {
9895
return false
9996
}
97+
98+
*n1 = n2
99+
return true
100100
}
101101

102102
// AdjustMaxIfPossible adjusts `*n1` to be `max(*n1, n2)`. Return true
103103
// iff `n2` was greater than or equal to `*n1`.
104104
func (n1 *Count64) AdjustMaxIfPossible(n2 Count64) bool {
105-
if n2 > *n1 {
106-
*n1 = n2
107-
return true
108-
} else {
105+
if n2 <= *n1 {
109106
return false
110107
}
108+
109+
*n1 = n2
110+
return true
111111
}

0 commit comments

Comments
 (0)