From b838c4c9f72df5bcbf1e4219c3e067bddee1018d Mon Sep 17 00:00:00 2001 From: Felix Lange Date: Mon, 8 Dec 2025 15:22:23 +0100 Subject: [PATCH] common/bitutil: remove safe fallback --- common/bitutil/bitutil.go | 13 ------------- common/bitutil/bitutil_test.go | 16 ++++++++++++++-- 2 files changed, 14 insertions(+), 15 deletions(-) diff --git a/common/bitutil/bitutil.go b/common/bitutil/bitutil.go index 1d169d5231..59b9562329 100644 --- a/common/bitutil/bitutil.go +++ b/common/bitutil/bitutil.go @@ -22,19 +22,6 @@ func XORBytes(dst, a, b []byte) int { return subtle.XORBytes(dst, a, b) } -// safeXORBytes xors one by one. It works on all architectures, independent if -// it supports unaligned read/writes or not. -func safeXORBytes(dst, a, b []byte) int { - n := len(a) - if len(b) < n { - n = len(b) - } - for i := 0; i < n; i++ { - dst[i] = a[i] ^ b[i] - } - return n -} - // ANDBytes ands the bytes in a and b. The destination is assumed to have enough // space. Returns the number of bytes and'd. func ANDBytes(dst, a, b []byte) int { diff --git a/common/bitutil/bitutil_test.go b/common/bitutil/bitutil_test.go index 12f3fe24a6..1748029794 100644 --- a/common/bitutil/bitutil_test.go +++ b/common/bitutil/bitutil_test.go @@ -29,7 +29,7 @@ func TestXOR(t *testing.T) { d2 := make([]byte, 1023+alignD)[alignD:] XORBytes(d1, p, q) - safeXORBytes(d2, p, q) + naiveXOR(d2, p, q) if !bytes.Equal(d1, d2) { t.Error("not equal", d1, d2) } @@ -38,6 +38,18 @@ func TestXOR(t *testing.T) { } } +// naiveXOR xors bytes one by one. +func naiveXOR(dst, a, b []byte) int { + n := len(a) + if len(b) < n { + n = len(b) + } + for i := 0; i < n; i++ { + dst[i] = a[i] ^ b[i] + } + return n +} + // Tests that bitwise AND works for various alignments. func TestAND(t *testing.T) { for alignP := 0; alignP < 2; alignP++ { @@ -134,7 +146,7 @@ func benchmarkBaseXOR(b *testing.B, size int) { p, q := make([]byte, size), make([]byte, size) for i := 0; i < b.N; i++ { - safeXORBytes(p, p, q) + naiveXOR(p, p, q) } }