FibImpl: remove unnecessary overhead
Neither the stream nor the copy is necessary.
@@ -223,10 +223,8 @@ public final class FibImpl implements Fib {
@Override
public Void visitNextHopIp(NextHopIp nextHopIp) {
- Set<AbstractRoute> lpmRoutes;
- lpmRoutes =
- rib
- .longestPrefixMatch(
+ Set<R> lpmRoutes =
+ rib.longestPrefixMatch(
nextHopIp.getIp(),
r -> {
if (route.getProtocol() == RoutingProtocol.STATIC) {
@@ -244,10 +242,7 @@ public final class FibImpl implements Fib {
}
// Recursive routes must pass restriction if present.
return restriction.test(r);
- })
- .stream()
- .map(AbstractRouteDecorator::getAbstractRoute)
- .collect(ImmutableSet.toImmutableSet());
+ });
if (lpmRoutes.isEmpty()
|| newSeenNetworks.contains(lpmRoutes.iterator().next().getNetwork())) {
@@ -260,14 +255,15 @@ public final class FibImpl implements Fib {
return null;
}
// We have at least one longest-prefix match, and have not looped yet.
- for (AbstractRoute nextHopLongestPrefixMatchRoute : lpmRoutes) {
+ for (R nextHopLongestPrefixMatchRoute : lpmRoutes) {
+ AbstractRoute genericRoute = nextHopLongestPrefixMatchRoute.getAbstractRoute();
buildResolutionTree(
rib,
- nextHopLongestPrefixMatchRoute,
+ genericRoute,
nextHopIp.getIp(),
newSeenNetworks,
depth + 1,
- ResolutionTreeNode.withParent(nextHopLongestPrefixMatchRoute, treeNode, null),
+ ResolutionTreeNode.withParent(genericRoute, treeNode, null),
restriction);
}
return null;
