Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tiny optimization: change type to Serializer to avoid type assertion #1448

Merged
merged 18 commits into from
Sep 9, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion protocol/dubbo/impl/codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,6 @@ func NewDubboCodec(reader *bufio.Reader) *ProtocolCodec {
pkgType: 0,
bodyLen: 0,
headerRead: false,
serializer: s.(Serializer),
serializer: s,
}
}
6 changes: 3 additions & 3 deletions protocol/dubbo/impl/serialization.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import (
)

var (
serializers = make(map[string]interface{})
serializers = make(map[string]Serializer)
nameMaps = make(map[byte]string)
)

Expand All @@ -37,11 +37,11 @@ func init() {
}
}

func SetSerializer(name string, serializer interface{}) {
func SetSerializer(name string, serializer Serializer) {
serializers[name] = serializer
}

func GetSerializerById(id byte) (interface{}, error) {
func GetSerializerById(id byte) (Serializer, error) {
name, ok := nameMaps[id]
if !ok {
panic(fmt.Sprintf("serialId %d not found", id))
Expand Down
2 changes: 1 addition & 1 deletion protocol/dubbo/impl/serialize.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,6 @@ func LoadSerializer(p *DubboPackage) error {
if err != nil {
panic(err)
}
p.SetSerializer(serializer.(Serializer))
p.SetSerializer(serializer)
return nil
}