✏️ 优化 getea

This commit is contained in:
fumiama 2021-11-26 18:48:05 +08:00
parent 9de065d31a
commit e6a20866b6

View File

@ -62,18 +62,6 @@ func init() {
}) })
} }
// Slice is the runtime representation of a slice.
// It cannot be used safely or portably and its representation may
// change in a later release.
//
// Unlike reflect.SliceHeader, its Data field is sufficient to guarantee the
// data it references will not be garbage collected.
type slice struct {
Data unsafe.Pointer
Len int
Cap int
}
func getea(key string) tea.TEA { func getea(key string) tea.TEA {
kr := []rune(key) kr := []rune(key)
if len(kr) > 4 { if len(kr) > 4 {
@ -83,8 +71,5 @@ func getea(key string) tea.TEA {
kr = append(kr, rune(4-len(kr))) kr = append(kr, rune(4-len(kr)))
} }
} }
skr := *(*slice)(unsafe.Pointer(&kr)) return *(*tea.TEA)(*(*unsafe.Pointer)(unsafe.Pointer(&kr)))
skr.Len *= 4
skr.Cap *= 4
return tea.NewTeaCipher(*(*[]byte)(unsafe.Pointer(&skr)))
} }