chore: change interface{} to any

main v1.1.4
NoahLan 1 year ago
parent ce131a3866
commit 7d47c277c8

@ -157,7 +157,7 @@ func (ac AhoCorasick) IterOverlappingByte(haystack []byte) Iter {
} }
var pool = sync.Pool{ var pool = sync.Pool{
New: func() interface{} { New: func() any {
return strings.Builder{} return strings.Builder{}
}, },
} }

@ -10,7 +10,7 @@ type startBytesThree struct {
byte3 byte byte3 byte
} }
func (s *startBytesThree) NextCandidate(_ *prefilterState, haystack []byte, at int) (interface{}, candidateType) { func (s *startBytesThree) NextCandidate(_ *prefilterState, haystack []byte, at int) (any, candidateType) {
for i, b := range haystack[at:] { for i, b := range haystack[at:] {
if s.byte1 == b || s.byte2 == b || s.byte3 == b { if s.byte1 == b || s.byte2 == b || s.byte3 == b {
return at + i, possibleStartOfMatchCandidate return at + i, possibleStartOfMatchCandidate
@ -44,7 +44,7 @@ type startBytesTwo struct {
byte2 byte byte2 byte
} }
func (s *startBytesTwo) NextCandidate(_ *prefilterState, haystack []byte, at int) (interface{}, candidateType) { func (s *startBytesTwo) NextCandidate(_ *prefilterState, haystack []byte, at int) (any, candidateType) {
for i, b := range haystack[at:] { for i, b := range haystack[at:] {
if s.byte1 == b || s.byte2 == b { if s.byte1 == b || s.byte2 == b {
return at + i, possibleStartOfMatchCandidate return at + i, possibleStartOfMatchCandidate
@ -77,7 +77,7 @@ type startBytesOne struct {
byte1 byte byte1 byte
} }
func (s *startBytesOne) NextCandidate(_ *prefilterState, haystack []byte, at int) (interface{}, candidateType) { func (s *startBytesOne) NextCandidate(_ *prefilterState, haystack []byte, at int) (any, candidateType) {
for i, b := range haystack[at:] { for i, b := range haystack[at:] {
if s.byte1 == b { if s.byte1 == b {
return at + i, possibleStartOfMatchCandidate return at + i, possibleStartOfMatchCandidate
@ -192,7 +192,7 @@ type rareBytesOne struct {
offset rareByteOffset offset rareByteOffset
} }
func (r *rareBytesOne) NextCandidate(state *prefilterState, haystack []byte, at int) (interface{}, candidateType) { func (r *rareBytesOne) NextCandidate(state *prefilterState, haystack []byte, at int) (any, candidateType) {
for i, b := range haystack[at:] { for i, b := range haystack[at:] {
if r.byte1 == b { if r.byte1 == b {
pos := at + i pos := at + i
@ -237,7 +237,7 @@ type rareBytesTwo struct {
byte2 byte byte2 byte
} }
func (r *rareBytesTwo) NextCandidate(state *prefilterState, haystack []byte, at int) (interface{}, candidateType) { func (r *rareBytesTwo) NextCandidate(state *prefilterState, haystack []byte, at int) (any, candidateType) {
for i, b := range haystack[at:] { for i, b := range haystack[at:] {
if r.byte1 == b || r.byte2 == b { if r.byte1 == b || r.byte2 == b {
pos := at + i pos := at + i
@ -283,7 +283,7 @@ type rareBytesThree struct {
byte3 byte byte3 byte
} }
func (r *rareBytesThree) NextCandidate(state *prefilterState, haystack []byte, at int) (interface{}, candidateType) { func (r *rareBytesThree) NextCandidate(state *prefilterState, haystack []byte, at int) (any, candidateType) {
for i, b := range haystack[at:] { for i, b := range haystack[at:] {
if r.byte1 == b || r.byte2 == b || r.byte3 == b { if r.byte1 == b || r.byte2 == b || r.byte3 == b {
pos := at + i pos := at + i
@ -577,14 +577,14 @@ const (
) )
type prefilter interface { type prefilter interface {
NextCandidate(state *prefilterState, haystack []byte, at int) (interface{}, candidateType) NextCandidate(state *prefilterState, haystack []byte, at int) (any, candidateType)
HeapBytes() int HeapBytes() int
ReportsFalsePositives() bool ReportsFalsePositives() bool
LooksForNonStartOfMatch() bool LooksForNonStartOfMatch() bool
clone() prefilter clone() prefilter
} }
func nextPrefilter(state *prefilterState, prefilter prefilter, haystack []byte, at int) (interface{}, candidateType) { func nextPrefilter(state *prefilterState, prefilter prefilter, haystack []byte, at int) (any, candidateType) {
candidate, typ := prefilter.NextCandidate(state, haystack, at) candidate, typ := prefilter.NextCandidate(state, haystack, at)
switch typ { switch typ {

@ -18,7 +18,7 @@ func NewPlainSerializer() ndef.Serializer {
} }
} }
func (s *PlainSerializer) Marshal(v interface{}) ([]byte, error) { func (s *PlainSerializer) Marshal(v any) ([]byte, error) {
ret, ok := v.(*PlainCommand) ret, ok := v.(*PlainCommand)
if !ok { if !ok {
return nil, errors.New(fmt.Sprintf("参数类型必须为 %T", PlainCommand{})) return nil, errors.New(fmt.Sprintf("参数类型必须为 %T", PlainCommand{}))
@ -36,7 +36,7 @@ func (s *PlainSerializer) Marshal(v interface{}) ([]byte, error) {
return []byte(sb.String()), nil return []byte(sb.String()), nil
} }
func (s *PlainSerializer) Unmarshal(data []byte, v interface{}) error { func (s *PlainSerializer) Unmarshal(data []byte, v any) error {
t, ok := v.(*PlainResp) t, ok := v.(*PlainResp)
if !ok { if !ok {
return errors.New(fmt.Sprintf("参数类型必须为 %T", PlainResp{})) return errors.New(fmt.Sprintf("参数类型必须为 %T", PlainResp{}))

Loading…
Cancel
Save