var castagnoliTable *Table
var castagnoliTable8 *slicing8Table
var updateCastagnoli func(crc uint32, p []byte) uint32
-var castagnoliOnce sync.Once
var haveCastagnoli atomic.Bool
-func castagnoliInit() {
+var castagnoliInitOnce = sync.OnceFunc(func() {
castagnoliTable = simpleMakeTable(Castagnoli)
if archAvailableCastagnoli() {
}
haveCastagnoli.Store(true)
-}
+})
// IEEETable is the table for the [IEEE] polynomial.
var IEEETable = simpleMakeTable(IEEE)
// ieeeTable8 is the slicing8Table for IEEE
var ieeeTable8 *slicing8Table
var updateIEEE func(crc uint32, p []byte) uint32
-var ieeeOnce sync.Once
-func ieeeInit() {
+var ieeeInitOnce = sync.OnceFunc(func() {
if archAvailableIEEE() {
archInitIEEE()
updateIEEE = archUpdateIEEE
return slicingUpdate(crc, ieeeTable8, p)
}
}
-}
+})
// MakeTable returns a [Table] constructed from the specified polynomial.
// The contents of this [Table] must not be modified.
func MakeTable(poly uint32) *Table {
switch poly {
case IEEE:
- ieeeOnce.Do(ieeeInit)
+ ieeeInitOnce()
return IEEETable
case Castagnoli:
- castagnoliOnce.Do(castagnoliInit)
+ castagnoliInitOnce()
return castagnoliTable
default:
return simpleMakeTable(poly)
// marshal and unmarshal the internal state of the hash.
func New(tab *Table) hash.Hash32 {
if tab == IEEETable {
- ieeeOnce.Do(ieeeInit)
+ ieeeInitOnce()
}
return &digest{0, tab}
}
return updateCastagnoli(crc, p)
case tab == IEEETable:
if checkInitIEEE {
- ieeeOnce.Do(ieeeInit)
+ ieeeInitOnce()
}
return updateIEEE(crc, p)
default:
// ChecksumIEEE returns the CRC-32 checksum of data
// using the [IEEE] polynomial.
func ChecksumIEEE(data []byte) uint32 {
- ieeeOnce.Do(ieeeInit)
+ ieeeInitOnce()
return updateIEEE(0, data)
}
type Table [256]uint64
var (
- slicing8TablesBuildOnce sync.Once
- slicing8TableISO *[8]Table
- slicing8TableECMA *[8]Table
+ slicing8TableISO *[8]Table
+ slicing8TableECMA *[8]Table
)
-func buildSlicing8TablesOnce() {
- slicing8TablesBuildOnce.Do(buildSlicing8Tables)
-}
+var buildSlicing8TablesOnce = sync.OnceFunc(buildSlicing8Tables)
func buildSlicing8Tables() {
slicing8TableISO = makeSlicingBy8Table(makeTable(ISO))