index the peer ID strings directly to avoid copying the byte slice

This commit is contained in:
vyzo 2019-05-17 23:36:46 +03:00
parent d340d2983e
commit afca355218
3 changed files with 6 additions and 12 deletions

View File

@ -21,23 +21,19 @@ func NewProtoBook(meta pstore.PeerMetadata) pstore.ProtoBook {
}
func (pb *dsProtoBook) Lock(p peer.ID) {
b := []byte(p)
pb.lks[b[len(b)-1]].Lock()
pb.lks[byte(p[len(p)-1])].Lock()
}
func (pb *dsProtoBook) Unlock(p peer.ID) {
b := []byte(p)
pb.lks[b[len(b)-1]].Unlock()
pb.lks[byte(p[len(p)-1])].Unlock()
}
func (pb *dsProtoBook) RLock(p peer.ID) {
b := []byte(p)
pb.lks[b[len(b)-1]].RLock()
pb.lks[byte(p[len(p)-1])].RLock()
}
func (pb *dsProtoBook) RUnlock(p peer.ID) {
b := []byte(p)
pb.lks[b[len(b)-1]].RUnlock()
pb.lks[byte(p[len(p)-1])].RUnlock()
}
func (pb *dsProtoBook) SetProtocols(p peer.ID, protos ...string) error {

View File

@ -40,8 +40,7 @@ type addrSegment struct {
}
func (s *addrSegments) get(p peer.ID) *addrSegment {
b := []byte(p)
return s[b[len(b)-1]]
return s[byte(p[len(p)-1])]
}
// memoryAddrBook manages addresses.

View File

@ -21,8 +21,7 @@ type protoSegment struct {
type protoSegments [256]*protoSegment
func (s *protoSegments) get(p peer.ID) *protoSegment {
b := []byte(p)
return s[b[len(b)-1]]
return s[byte(p[len(p)-1])]
}
type memoryProtoBook struct {