mirror of
https://github.com/libp2p/go-libp2p-peerstore.git
synced 2025-03-27 13:30:11 +08:00
index the peer ID strings directly to avoid copying the byte slice
This commit is contained in:
parent
d340d2983e
commit
afca355218
@ -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 {
|
||||
|
Loading…
Reference in New Issue
Block a user