mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
cmd/compile: special-case const comparisons against zero
Constant comparisons against 0 are reasonably common. Special-case and avoid allocating a new zero value each time. Change-Id: I6c526c8ab30ef7f0fef59110133c764b7b90ba05 Reviewed-on: https://go-review.googlesource.com/20956 Reviewed-by: Alan Donovan <adonovan@google.com>
This commit is contained in:
parent
d3253876f2
commit
07749aef98
3 changed files with 11 additions and 10 deletions
|
|
@ -116,11 +116,11 @@ func (a *Mpflt) Cmp(b *Mpflt) int {
|
|||
return a.Val.Cmp(&b.Val)
|
||||
}
|
||||
|
||||
func (b *Mpflt) CmpFloat64(c float64) int {
|
||||
var a Mpflt
|
||||
|
||||
a.SetFloat64(c)
|
||||
return b.Cmp(&a)
|
||||
func (a *Mpflt) CmpFloat64(c float64) int {
|
||||
if c == 0 {
|
||||
return a.Val.Sign() // common case shortcut
|
||||
}
|
||||
return a.Val.Cmp(big.NewFloat(c))
|
||||
}
|
||||
|
||||
func (a *Mpflt) Float64() float64 {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue