@@ -2,19 +2,19 @@ package base64
22
33import (
44 "encoding/base64"
5- "unsafe"
65
76 "github.com/segmentio/asm/cpu"
7+ "github.com/segmentio/asm/internal/unsafebytes"
88)
99
1010// An Encoding is a radix 64 encoding/decoding scheme, defined by a
1111// 64-character alphabet.
1212type Encoding struct {
13- enc func (dst []byte , src []byte , lut [ 16 ] int8 ) (int , int )
14- enclut [16 ]int8
13+ enc func (dst []byte , src []byte , lut * int8 ) (int , int )
14+ enclut [32 ]int8
1515
16- dec func (dst []byte , src []byte , lut [ 32 ] int8 ) (int , int )
17- declut [32 ]int8
16+ dec func (dst []byte , src []byte , lut * int8 ) (int , int )
17+ declut [48 ]int8
1818
1919 base * base64.Encoding
2020}
@@ -42,7 +42,7 @@ func (e *Encoding) enableEncodeAVX2(encoder string) {
4242 // [52..61] [48..57] -4 [2..11] 0123456789
4343 // [62] [43] -19 12 +
4444 // [63] [47] -16 13 /
45- tab := [16 ]int8 {int8 (encoder [0 ]), int8 (encoder [letterRange ]) - letterRange }
45+ tab := [32 ]int8 {int8 (encoder [0 ]), int8 (encoder [letterRange ]) - letterRange }
4646 for i , ch := range encoder [2 * letterRange :] {
4747 tab [2 + i ] = int8 (ch ) - 2 * letterRange - int8 (i )
4848 }
@@ -67,7 +67,7 @@ func (e *Encoding) enableDecodeAVX2(encoder string) {
6767 // [48..57] [52..61] +4 3 0123456789
6868 // [65..90] [0..25] -65 4,5 ABCDEFGHIJKLMNOPQRSTUVWXYZ
6969 // [97..122] [26..51] -71 6,7 abcdefghijklmnopqrstuvwxyz
70- tab := [32 ]int8 {
70+ tab := [48 ]int8 {
7171 0 , 63 - c63 , 62 - c62 , 4 , - 65 , - 65 , - 71 , - 71 ,
7272 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ,
7373 0x15 , 0x11 , 0x11 , 0x11 , 0x11 , 0x11 , 0x11 , 0x11 ,
@@ -104,7 +104,7 @@ func (enc Encoding) Strict() *Encoding {
104104// This will write EncodedLen(len(src)) bytes to dst.
105105func (enc * Encoding ) Encode (dst , src []byte ) {
106106 if len (src ) >= minEncodeLen && enc .enc != nil {
107- d , s := enc .enc (dst , src , enc .enclut )
107+ d , s := enc .enc (dst , src , & enc .enclut [ 0 ] )
108108 dst = dst [d :]
109109 src = src [s :]
110110 }
@@ -131,7 +131,7 @@ func (enc *Encoding) EncodedLen(n int) int {
131131func (enc * Encoding ) Decode (dst , src []byte ) (n int , err error ) {
132132 var d , s int
133133 if len (src ) >= minDecodeLen && enc .dec != nil {
134- d , s = enc .dec (dst , src , enc .declut )
134+ d , s = enc .dec (dst , src , & enc .declut [ 0 ] )
135135 dst = dst [d :]
136136 src = src [s :]
137137 }
@@ -143,7 +143,7 @@ func (enc *Encoding) Decode(dst, src []byte) (n int, err error) {
143143// DecodeString decodes the base64 encoded string s, returns the decoded
144144// value as bytes.
145145func (enc * Encoding ) DecodeString (s string ) ([]byte , error ) {
146- src := * ( * [] byte )( unsafe . Pointer ( & s ) )
146+ src := unsafebytes . BytesOf ( s )
147147 dst := make ([]byte , enc .base .DecodedLen (len (s )))
148148 n , err := enc .Decode (dst , src )
149149 return dst [:n ], err
0 commit comments