@@ -27,10 +27,7 @@ func XORBytes(dst, a, b []byte) int {
2727// fastXORBytes xors in bulk. It only works on architectures that support
2828// unaligned read/writes.
2929func fastXORBytes (dst , a , b []byte ) int {
30- n := len (a )
31- if len (b ) < n {
32- n = len (b )
33- }
30+ n := min (len (b ), len (a ))
3431 w := n / wordSize
3532 if w > 0 {
3633 dw := * (* []uintptr )(unsafe .Pointer (& dst ))
@@ -49,10 +46,7 @@ func fastXORBytes(dst, a, b []byte) int {
4946// safeXORBytes xors one by one. It works on all architectures, independent if
5047// it supports unaligned read/writes or not.
5148func safeXORBytes (dst , a , b []byte ) int {
52- n := len (a )
53- if len (b ) < n {
54- n = len (b )
55- }
49+ n := min (len (b ), len (a ))
5650 for i := 0 ; i < n ; i ++ {
5751 dst [i ] = a [i ] ^ b [i ]
5852 }
@@ -71,10 +65,7 @@ func ANDBytes(dst, a, b []byte) int {
7165// fastANDBytes ands in bulk. It only works on architectures that support
7266// unaligned read/writes.
7367func fastANDBytes (dst , a , b []byte ) int {
74- n := len (a )
75- if len (b ) < n {
76- n = len (b )
77- }
68+ n := min (len (b ), len (a ))
7869 w := n / wordSize
7970 if w > 0 {
8071 dw := * (* []uintptr )(unsafe .Pointer (& dst ))
@@ -93,10 +84,7 @@ func fastANDBytes(dst, a, b []byte) int {
9384// safeANDBytes ands one by one. It works on all architectures, independent if
9485// it supports unaligned read/writes or not.
9586func safeANDBytes (dst , a , b []byte ) int {
96- n := len (a )
97- if len (b ) < n {
98- n = len (b )
99- }
87+ n := min (len (b ), len (a ))
10088 for i := 0 ; i < n ; i ++ {
10189 dst [i ] = a [i ] & b [i ]
10290 }
@@ -115,10 +103,7 @@ func ORBytes(dst, a, b []byte) int {
115103// fastORBytes ors in bulk. It only works on architectures that support
116104// unaligned read/writes.
117105func fastORBytes (dst , a , b []byte ) int {
118- n := len (a )
119- if len (b ) < n {
120- n = len (b )
121- }
106+ n := min (len (b ), len (a ))
122107 w := n / wordSize
123108 if w > 0 {
124109 dw := * (* []uintptr )(unsafe .Pointer (& dst ))
@@ -137,10 +122,7 @@ func fastORBytes(dst, a, b []byte) int {
137122// safeORBytes ors one by one. It works on all architectures, independent if
138123// it supports unaligned read/writes or not.
139124func safeORBytes (dst , a , b []byte ) int {
140- n := len (a )
141- if len (b ) < n {
142- n = len (b )
143- }
125+ n := min (len (b ), len (a ))
144126 for i := 0 ; i < n ; i ++ {
145127 dst [i ] = a [i ] | b [i ]
146128 }
0 commit comments