mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-17 17:33:47 +00:00
p2p/enr: simplify Set
This commit is contained in:
parent
96431d83c9
commit
260989e77d
1 changed files with 3 additions and 11 deletions
|
|
@ -89,29 +89,21 @@ func (r *Record) Set(k Key) error {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
var inserted bool
|
|
||||||
for i, p := range r.pairs {
|
for i, p := range r.pairs {
|
||||||
if p.k == k.ENRKey() {
|
if p.k == k.ENRKey() {
|
||||||
// replace value of pair
|
// replace value of pair
|
||||||
r.pairs[i].v = blob
|
r.pairs[i].v = blob
|
||||||
inserted = true
|
return nil
|
||||||
|
|
||||||
break
|
|
||||||
} else if p.k > k.ENRKey() {
|
} else if p.k > k.ENRKey() {
|
||||||
// insert pair before i-th elem
|
// insert pair before i-th elem
|
||||||
el := pair{k.ENRKey(), blob}
|
el := pair{k.ENRKey(), blob}
|
||||||
|
|
||||||
r.pairs = append(r.pairs, pair{})
|
r.pairs = append(r.pairs, pair{})
|
||||||
copy(r.pairs[i+1:], r.pairs[i:])
|
copy(r.pairs[i+1:], r.pairs[i:])
|
||||||
r.pairs[i] = el
|
r.pairs[i] = el
|
||||||
|
return nil
|
||||||
inserted = true
|
|
||||||
break
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if !inserted {
|
|
||||||
r.pairs = append(r.pairs, pair{k.ENRKey(), blob})
|
r.pairs = append(r.pairs, pair{k.ENRKey(), blob})
|
||||||
}
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue