Skip to content

Commit d2db237

Browse files
committed
hash/maphash: move purego-only helper functions to build tagged file
Hash.float64 and btoi helper functions are used only in the purego version. Move them to the build tagged file. Change-Id: I57f9a48966573ab0aee1de759eeddd2331967870 Reviewed-on: https://go-review.googlesource.com/c/go/+/675158 Reviewed-by: David Chase <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]>
1 parent 5e6a868 commit d2db237

File tree

2 files changed

+23
-24
lines changed

2 files changed

+23
-24
lines changed

src/hash/maphash/maphash.go

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@ package maphash
1515
import (
1616
"hash"
1717
"internal/abi"
18-
"internal/byteorder"
19-
"math"
2018
)
2119

2220
// A Seed is a random value that selects the specific hash function
@@ -310,25 +308,3 @@ func WriteComparable[T comparable](h *Hash, x T) {
310308
}
311309
writeComparable(h, x)
312310
}
313-
314-
func (h *Hash) float64(f float64) {
315-
if f == 0 {
316-
h.WriteByte(0)
317-
return
318-
}
319-
var buf [8]byte
320-
if f != f {
321-
byteorder.LEPutUint64(buf[:], randUint64())
322-
h.Write(buf[:])
323-
return
324-
}
325-
byteorder.LEPutUint64(buf[:], math.Float64bits(f))
326-
h.Write(buf[:])
327-
}
328-
329-
func btoi(b bool) byte {
330-
if b {
331-
return 1
332-
}
333-
return 0
334-
}

src/hash/maphash/maphash_purego.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"crypto/rand"
1111
"errors"
1212
"internal/byteorder"
13+
"math"
1314
"math/bits"
1415
"reflect"
1516
)
@@ -175,3 +176,25 @@ func appendT(h *Hash, v reflect.Value) {
175176
}
176177
panic(errors.New("maphash: hash of unhashable type " + v.Type().String()))
177178
}
179+
180+
func (h *Hash) float64(f float64) {
181+
if f == 0 {
182+
h.WriteByte(0)
183+
return
184+
}
185+
var buf [8]byte
186+
if f != f {
187+
byteorder.LEPutUint64(buf[:], randUint64())
188+
h.Write(buf[:])
189+
return
190+
}
191+
byteorder.LEPutUint64(buf[:], math.Float64bits(f))
192+
h.Write(buf[:])
193+
}
194+
195+
func btoi(b bool) byte {
196+
if b {
197+
return 1
198+
}
199+
return 0
200+
}

0 commit comments

Comments
 (0)