1
0
mirror of https://github.com/fafhrd91/actix-net synced 2025-01-31 07:02:08 +01:00

leak string instead of rc

This commit is contained in:
Nikolay Kim 2019-12-31 12:04:35 +06:00
parent 5779da0f49
commit 974bd6b01e
4 changed files with 16 additions and 13 deletions

View File

@ -1,5 +1,7 @@
# Changes
## [0.2.4] - 2019-12-xx
## [0.2.3] - 2019-12-25
* Add impl `IntoPattern` for `&String`

View File

@ -1,6 +1,6 @@
[package]
name = "actix-router"
version = "0.2.3"
version = "0.2.4"
authors = ["Nikolay Kim <fafhrd91@gmail.com>"]
description = "Path router"
keywords = ["actix"]

View File

@ -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<T> {
path: T,
pub(crate) skip: u16,
pub(crate) segments: Vec<(Rc<String>, PathItem)>,
pub(crate) segments: Vec<(&'static str, PathItem)>,
}
impl<T: Default> Default for Path<T> {
@ -96,7 +95,7 @@ impl<T: ResourcePath> Path<T> {
self.skip += n;
}
pub(crate) fn add(&mut self, name: Rc<String>, 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<T: ResourcePath> Path<T> {
}
#[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<T: ResourcePath> Path<T> {
/// 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) => {

View File

@ -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<Rc<String>>, usize),
DynamicSet(RegexSet, Vec<(Regex, Vec<Rc<String>>, 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 {