Commit afca3552 authored by vyzo's avatar vyzo

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

parent d340d298
......@@ -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 {
......
......@@ -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.
......
......@@ -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 {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment