refactor: extract nameserver GossipData.copy

and remove a self-evident comment
This commit is contained in:
Matthias Radestock committed 2015-11-18 11:30:40 +00:00
1 parent 3cd199e852
commit 1500b1dc00
1 file changed
+8 -8
+8 -8
View File
@@ -247,11 +247,7 @@ type GossipData struct {
func (g *GossipData) Merge(o mesh.GossipData) mesh.GossipData {
other := o.(*GossipData)
gossip := &GossipData{
Entries: make(Entries, len(g.Entries)),
Timestamp: g.Timestamp,
}
copy(gossip.Entries, g.Entries)
gossip := g.copy()
gossip.Entries.merge(other.Entries)
if gossip.Timestamp < other.Timestamp {
gossip.Timestamp = other.Timestamp
@@ -270,9 +266,7 @@ func (g *GossipData) Decode(msg []byte) error {
}
func (g *GossipData) Encode() [][]byte {
// Make a copy so we can sort: all outgoing data is sent in case-sensitive order
g2 := GossipData{Timestamp: g.Timestamp, Entries: make(Entries, len(g.Entries))}
copy(g2.Entries, g.Entries)
g2 := g.copy()
sort.Sort(CaseSensitive(g2.Entries))
buf := &bytes.Buffer{}
if err := gob.NewEncoder(buf).Encode(g2); err != nil {
@@ -280,3 +274,9 @@ func (g *GossipData) Encode() [][]byte {
}
return [][]byte{buf.Bytes()}
}
func (g *GossipData) copy() *GossipData {
g2 := &GossipData{Timestamp: g.Timestamp, Entries: make(Entries, len(g.Entries))}
copy(g2.Entries, g.Entries)
return g2
}