mirror of
https://github.com/fafhrd91/actix-net
synced 2025-01-31 12:42:09 +01:00
leak string instead of rc
This commit is contained in:
parent
5779da0f49
commit
974bd6b01e
@ -1,5 +1,7 @@
|
|||||||
# Changes
|
# Changes
|
||||||
|
|
||||||
|
## [0.2.4] - 2019-12-xx
|
||||||
|
|
||||||
## [0.2.3] - 2019-12-25
|
## [0.2.3] - 2019-12-25
|
||||||
|
|
||||||
* Add impl `IntoPattern` for `&String`
|
* Add impl `IntoPattern` for `&String`
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "actix-router"
|
name = "actix-router"
|
||||||
version = "0.2.3"
|
version = "0.2.4"
|
||||||
authors = ["Nikolay Kim <fafhrd91@gmail.com>"]
|
authors = ["Nikolay Kim <fafhrd91@gmail.com>"]
|
||||||
description = "Path router"
|
description = "Path router"
|
||||||
keywords = ["actix"]
|
keywords = ["actix"]
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
use std::ops::Index;
|
use std::ops::Index;
|
||||||
use std::rc::Rc;
|
|
||||||
|
|
||||||
use serde::de;
|
use serde::de;
|
||||||
|
|
||||||
@ -19,7 +18,7 @@ pub(crate) enum PathItem {
|
|||||||
pub struct Path<T> {
|
pub struct Path<T> {
|
||||||
path: T,
|
path: T,
|
||||||
pub(crate) skip: u16,
|
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> {
|
impl<T: Default> Default for Path<T> {
|
||||||
@ -96,7 +95,7 @@ impl<T: ResourcePath> Path<T> {
|
|||||||
self.skip += n;
|
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 {
|
match value {
|
||||||
PathItem::Static(s) => self.segments.push((name, PathItem::Static(s))),
|
PathItem::Static(s) => self.segments.push((name, PathItem::Static(s))),
|
||||||
PathItem::Segment(begin, end) => self
|
PathItem::Segment(begin, end) => self
|
||||||
@ -106,9 +105,8 @@ impl<T: ResourcePath> Path<T> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[doc(hidden)]
|
#[doc(hidden)]
|
||||||
pub fn add_static(&mut self, name: &str, value: &'static str) {
|
pub fn add_static(&mut self, name: &'static str, value: &'static str) {
|
||||||
self.segments
|
self.segments.push((name, PathItem::Static(value)));
|
||||||
.push((Rc::new(name.to_string()), PathItem::Static(value)));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
@ -126,7 +124,7 @@ impl<T: ResourcePath> Path<T> {
|
|||||||
/// Get matched parameter by name without type conversion
|
/// Get matched parameter by name without type conversion
|
||||||
pub fn get(&self, key: &str) -> Option<&str> {
|
pub fn get(&self, key: &str) -> Option<&str> {
|
||||||
for item in self.segments.iter() {
|
for item in self.segments.iter() {
|
||||||
if key == item.0.as_str() {
|
if key == item.0 {
|
||||||
return match item.1 {
|
return match item.1 {
|
||||||
PathItem::Static(ref s) => Some(&s),
|
PathItem::Static(ref s) => Some(&s),
|
||||||
PathItem::Segment(s, e) => {
|
PathItem::Segment(s, e) => {
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
use std::cmp::min;
|
use std::cmp::min;
|
||||||
use std::hash::{Hash, Hasher};
|
use std::hash::{Hash, Hasher};
|
||||||
use std::rc::Rc;
|
|
||||||
|
|
||||||
use regex::{escape, Regex, RegexSet};
|
use regex::{escape, Regex, RegexSet};
|
||||||
|
|
||||||
@ -31,8 +30,8 @@ enum PatternElement {
|
|||||||
enum PatternType {
|
enum PatternType {
|
||||||
Static(String),
|
Static(String),
|
||||||
Prefix(String),
|
Prefix(String),
|
||||||
Dynamic(Regex, Vec<Rc<String>>, usize),
|
Dynamic(Regex, Vec<&'static str>, usize),
|
||||||
DynamicSet(RegexSet, Vec<(Regex, Vec<Rc<String>>, usize)>),
|
DynamicSet(RegexSet, Vec<(Regex, Vec<&'static str>, usize)>),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ResourceDef {
|
impl ResourceDef {
|
||||||
@ -58,7 +57,9 @@ impl ResourceDef {
|
|||||||
// actix creates one router per thread
|
// actix creates one router per thread
|
||||||
let names: Vec<_> = re
|
let names: Vec<_> = re
|
||||||
.capture_names()
|
.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();
|
.collect();
|
||||||
data.push((re, names, len));
|
data.push((re, names, len));
|
||||||
re_set.push(pattern);
|
re_set.push(pattern);
|
||||||
@ -117,7 +118,9 @@ impl ResourceDef {
|
|||||||
// actix creates one router per thread
|
// actix creates one router per thread
|
||||||
let names = re
|
let names = re
|
||||||
.capture_names()
|
.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();
|
.collect();
|
||||||
PatternType::Dynamic(re, names, len)
|
PatternType::Dynamic(re, names, len)
|
||||||
} else if for_prefix {
|
} else if for_prefix {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user