From b9c8506c23b4d1c0e1f1beba11561be8a65572c2 Mon Sep 17 00:00:00 2001 From: Darien Raymond Date: Tue, 20 Nov 2018 12:25:56 +0100 Subject: [PATCH] optimize network matcher --- app/router/condition.go | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/app/router/condition.go b/app/router/condition.go index 54fe9264b..ccf3c08d6 100644 --- a/app/router/condition.go +++ b/app/router/condition.go @@ -182,21 +182,23 @@ func (v *PortMatcher) Apply(ctx context.Context) bool { } type NetworkMatcher struct { - network *net.NetworkList + list [8]bool } -func NewNetworkMatcher(network *net.NetworkList) *NetworkMatcher { - return &NetworkMatcher{ - network: network, +func NewNetworkMatcher(network *net.NetworkList) NetworkMatcher { + var matcher NetworkMatcher + for _, n := range network.Network { + matcher.list[int(n)] = true } + return matcher } -func (v *NetworkMatcher) Apply(ctx context.Context) bool { +func (v NetworkMatcher) Apply(ctx context.Context) bool { outbound := session.OutboundFromContext(ctx) if outbound == nil || !outbound.Target.IsValid() { return false } - return v.network.HasNetwork(outbound.Target.Network) + return v.list[int(outbound.Target.Network)] } type UserMatcher struct {