diff --git a/src/bytes/bytes_test.go b/src/bytes/bytes_test.go index f0733edd3f4..5e8cf85fd90 100644 --- a/src/bytes/bytes_test.go +++ b/src/bytes/bytes_test.go @@ -629,6 +629,11 @@ func BenchmarkEqual(b *testing.B) { }) sizes := []int{1, 6, 9, 15, 16, 20, 32, 4 << 10, 4 << 20, 64 << 20} + + b.Run("same", func(b *testing.B) { + benchBytes(b, sizes, bmEqual(func(a, b []byte) bool { return Equal(a, a) })) + }) + benchBytes(b, sizes, bmEqual(Equal)) } diff --git a/src/internal/bytealg/equal_arm64.s b/src/internal/bytealg/equal_arm64.s index d3aabba5871..4db95154744 100644 --- a/src/internal/bytealg/equal_arm64.s +++ b/src/internal/bytealg/equal_arm64.s @@ -9,6 +9,9 @@ TEXT runtime·memequal(SB),NOSPLIT|NOFRAME,$0-25 // short path to handle 0-byte case CBZ R2, equal + // short path to handle equal pointers + CMP R0, R1 + BEQ equal B memeqbody<>(SB) equal: MOVD $1, R0