From e52ad631ccc09b12d19934f5bad2b8efe039588d Mon Sep 17 00:00:00 2001 From: Daniel Czerwonk <daniel@dan-nrw.de> Date: Thu, 17 May 2018 13:59:10 +0200 Subject: [PATCH] improved performance on as path prepend --- route/bgp.go | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/route/bgp.go b/route/bgp.go index 0942770d..e56b140b 100644 --- a/route/bgp.go +++ b/route/bgp.go @@ -2,6 +2,8 @@ package route import ( "fmt" + "strconv" + "strings" "github.com/taktv6/tflow2/convert" ) @@ -155,11 +157,20 @@ func (b *BGPPath) Print() string { } func (b *BGPPath) Prepend(asn uint32, times uint16) { + if times == 0 { + return + } + + asnStr := strconv.FormatUint(uint64(asn), 10) + + path := make([]string, times+1) for i := 0; uint16(i) < times; i++ { - b.ASPath = fmt.Sprintf("%d %s", asn, b.ASPath) + path[i] = asnStr } + path[times] = b.ASPath - b.ASPathLen = b.ASPathLen + uint16(times) + b.ASPath = strings.TrimSuffix(strings.Join(path, " "), " ") + b.ASPathLen = b.ASPathLen + times } func (p *BGPPath) Copy() *BGPPath { -- GitLab