From 85f5511313479f946caa3b0e80a7113e439afcee Mon Sep 17 00:00:00 2001 From: David Pedersen Date: Mon, 25 Oct 2021 21:30:35 +0200 Subject: [PATCH] Small routing cleanup Storing the paths like this should be slightly more efficient. --- src/routing/mod.rs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/routing/mod.rs b/src/routing/mod.rs index 56970452..0d54f97e 100644 --- a/src/routing/mod.rs +++ b/src/routing/mod.rs @@ -20,6 +20,7 @@ use std::{ fmt, future::ready, marker::PhantomData, + sync::Arc, task::{Context, Poll}, }; use tower::{util::ServiceExt, ServiceBuilder}; @@ -1055,10 +1056,11 @@ impl Service> for Route { } } +/// Wrapper around `matchit::Node` that supports merging two `Node`s. #[derive(Clone, Default)] struct Node { inner: matchit::Node, - paths: Vec<(String, RouteId)>, + paths: Vec<(Arc, RouteId)>, } impl Node { @@ -1069,13 +1071,13 @@ impl Node { ) -> Result<(), matchit::InsertError> { let path = path.into(); self.inner.insert(&path, val)?; - self.paths.push((path, val)); + self.paths.push((path.into(), val)); Ok(()) } fn merge(&mut self, other: Node) -> Result<(), matchit::InsertError> { for (path, id) in other.paths { - self.insert(path, id)?; + self.insert(&*path, id)?; } Ok(()) }