diff --git a/router/CHANGES.txt b/router/CHANGES.txt index 558baeb9..c9283566 100644 --- a/router/CHANGES.txt +++ b/router/CHANGES.txt @@ -1,5 +1,7 @@ # Changes +## [0.2.4] - 2019-12-xx + ## [0.2.3] - 2019-12-25 * Add impl `IntoPattern` for `&String` diff --git a/router/Cargo.toml b/router/Cargo.toml index 419ae5ea..1e5f4d54 100644 --- a/router/Cargo.toml +++ b/router/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "actix-router" -version = "0.2.3" +version = "0.2.4" authors = ["Nikolay Kim "] description = "Path router" keywords = ["actix"] diff --git a/router/src/path.rs b/router/src/path.rs index 19432c17..0e13c37a 100644 --- a/router/src/path.rs +++ b/router/src/path.rs @@ -1,5 +1,4 @@ use std::ops::Index; -use std::rc::Rc; use serde::de; @@ -19,7 +18,7 @@ pub(crate) enum PathItem { pub struct Path { path: T, pub(crate) skip: u16, - pub(crate) segments: Vec<(Rc, PathItem)>, + pub(crate) segments: Vec<(&'static str, PathItem)>, } impl Default for Path { @@ -96,7 +95,7 @@ impl Path { self.skip += n; } - pub(crate) fn add(&mut self, name: Rc, value: PathItem) { + pub(crate) fn add(&mut self, name: &'static str, value: PathItem) { match value { PathItem::Static(s) => self.segments.push((name, PathItem::Static(s))), PathItem::Segment(begin, end) => self @@ -106,9 +105,8 @@ impl Path { } #[doc(hidden)] - pub fn add_static(&mut self, name: &str, value: &'static str) { - self.segments - .push((Rc::new(name.to_string()), PathItem::Static(value))); + pub fn add_static(&mut self, name: &'static str, value: &'static str) { + self.segments.push((name, PathItem::Static(value))); } #[inline] @@ -126,7 +124,7 @@ impl Path { /// Get matched parameter by name without type conversion pub fn get(&self, key: &str) -> Option<&str> { for item in self.segments.iter() { - if key == item.0.as_str() { + if key == item.0 { return match item.1 { PathItem::Static(ref s) => Some(&s), PathItem::Segment(s, e) => { diff --git a/router/src/resource.rs b/router/src/resource.rs index 8db1cfe2..999bedfe 100644 --- a/router/src/resource.rs +++ b/router/src/resource.rs @@ -1,6 +1,5 @@ use std::cmp::min; use std::hash::{Hash, Hasher}; -use std::rc::Rc; use regex::{escape, Regex, RegexSet}; @@ -31,8 +30,8 @@ enum PatternElement { enum PatternType { Static(String), Prefix(String), - Dynamic(Regex, Vec>, usize), - DynamicSet(RegexSet, Vec<(Regex, Vec>, usize)>), + Dynamic(Regex, Vec<&'static str>, usize), + DynamicSet(RegexSet, Vec<(Regex, Vec<&'static str>, usize)>), } impl ResourceDef { @@ -58,7 +57,9 @@ impl ResourceDef { // actix creates one router per thread let names: Vec<_> = re .capture_names() - .filter_map(|name| name.map(|name| Rc::new(name.to_owned()))) + .filter_map(|name| { + name.map(|name| Box::leak(Box::new(name.to_owned())).as_str()) + }) .collect(); data.push((re, names, len)); re_set.push(pattern); @@ -117,7 +118,9 @@ impl ResourceDef { // actix creates one router per thread let names = re .capture_names() - .filter_map(|name| name.map(|name| Rc::new(name.to_owned()))) + .filter_map(|name| { + name.map(|name| Box::leak(Box::new(name.to_owned())).as_str()) + }) .collect(); PatternType::Dynamic(re, names, len) } else if for_prefix {