Skip to content

Commit 134cd34

Browse files
cuiweixiegopherbot
authored andcommitted
hash: convert haveCastagnoli to atomic type
Change-Id: I313fff5684d89ee737572d11b1b697c5575866a8 Reviewed-on: https://go-review.googlesource.com/c/go/+/426083 Reviewed-by: Keith Randall <[email protected]> TryBot-Result: Gopher Robot <[email protected]> Reviewed-by: Michael Pratt <[email protected]> Run-TryBot: Keith Randall <[email protected]> Auto-Submit: Keith Randall <[email protected]> Reviewed-by: Keith Randall <[email protected]>
1 parent 8e35910 commit 134cd34

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

src/hash/crc32/crc32.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ var castagnoliTable *Table
7878
var castagnoliTable8 *slicing8Table
7979
var updateCastagnoli func(crc uint32, p []byte) uint32
8080
var castagnoliOnce sync.Once
81-
var haveCastagnoli uint32
81+
var haveCastagnoli atomic.Bool
8282

8383
func castagnoliInit() {
8484
castagnoliTable = simpleMakeTable(Castagnoli)
@@ -94,7 +94,7 @@ func castagnoliInit() {
9494
}
9595
}
9696

97-
atomic.StoreUint32(&haveCastagnoli, 1)
97+
haveCastagnoli.Store(true)
9898
}
9999

100100
// IEEETable is the table for the IEEE polynomial.
@@ -208,7 +208,7 @@ func readUint32(b []byte) uint32 {
208208
// Update returns the result of adding the bytes in p to the crc.
209209
func Update(crc uint32, tab *Table, p []byte) uint32 {
210210
switch {
211-
case atomic.LoadUint32(&haveCastagnoli) != 0 && tab == castagnoliTable:
211+
case haveCastagnoli.Load() && tab == castagnoliTable:
212212
return updateCastagnoli(crc, p)
213213
case tab == IEEETable:
214214
// Unfortunately, because IEEETable is exported, IEEE may be used without a
@@ -222,7 +222,7 @@ func Update(crc uint32, tab *Table, p []byte) uint32 {
222222

223223
func (d *digest) Write(p []byte) (n int, err error) {
224224
switch {
225-
case atomic.LoadUint32(&haveCastagnoli) != 0 && d.tab == castagnoliTable:
225+
case haveCastagnoli.Load() && d.tab == castagnoliTable:
226226
d.crc = updateCastagnoli(d.crc, p)
227227
case d.tab == IEEETable:
228228
// We only create digest objects through New() which takes care of

0 commit comments

Comments
 (0)