mirror of
https://github.com/actix/actix-web.git
synced 2024-12-30 12:00:38 +00:00
replace tinyvec with smallvec (#1866)
This commit is contained in:
parent
522c9a5ea6
commit
3beb4cf2da
3 changed files with 13 additions and 9 deletions
|
@ -107,7 +107,7 @@ time = { version = "0.2.7", default-features = false, features = ["std"] }
|
||||||
url = "2.1"
|
url = "2.1"
|
||||||
open-ssl = { package = "openssl", version = "0.10", optional = true }
|
open-ssl = { package = "openssl", version = "0.10", optional = true }
|
||||||
rust-tls = { package = "rustls", version = "0.18.0", optional = true }
|
rust-tls = { package = "rustls", version = "0.18.0", optional = true }
|
||||||
tinyvec = { version = "1", features = ["alloc"] }
|
smallvec = "1.6"
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
actix = "0.10.0"
|
actix = "0.10.0"
|
||||||
|
|
|
@ -10,7 +10,6 @@ use actix_router::{Path, ResourceDef, ResourceInfo, Router, Url};
|
||||||
use actix_service::boxed::{self, BoxService, BoxServiceFactory};
|
use actix_service::boxed::{self, BoxService, BoxServiceFactory};
|
||||||
use actix_service::{fn_service, Service, ServiceFactory};
|
use actix_service::{fn_service, Service, ServiceFactory};
|
||||||
use futures_util::future::{join_all, ok, FutureExt, LocalBoxFuture};
|
use futures_util::future::{join_all, ok, FutureExt, LocalBoxFuture};
|
||||||
use tinyvec::tiny_vec;
|
|
||||||
|
|
||||||
use crate::config::{AppConfig, AppService};
|
use crate::config::{AppConfig, AppService};
|
||||||
use crate::data::{DataFactory, FnDataFactory};
|
use crate::data::{DataFactory, FnDataFactory};
|
||||||
|
@ -246,7 +245,6 @@ where
|
||||||
inner.path.reset();
|
inner.path.reset();
|
||||||
inner.head = head;
|
inner.head = head;
|
||||||
inner.payload = payload;
|
inner.payload = payload;
|
||||||
inner.app_data = tiny_vec![self.data.clone()];
|
|
||||||
req
|
req
|
||||||
} else {
|
} else {
|
||||||
HttpRequest::new(
|
HttpRequest::new(
|
||||||
|
|
|
@ -6,7 +6,7 @@ use actix_http::http::{HeaderMap, Method, Uri, Version};
|
||||||
use actix_http::{Error, Extensions, HttpMessage, Message, Payload, RequestHead};
|
use actix_http::{Error, Extensions, HttpMessage, Message, Payload, RequestHead};
|
||||||
use actix_router::{Path, Url};
|
use actix_router::{Path, Url};
|
||||||
use futures_util::future::{ok, Ready};
|
use futures_util::future::{ok, Ready};
|
||||||
use tinyvec::TinyVec;
|
use smallvec::SmallVec;
|
||||||
|
|
||||||
use crate::config::AppConfig;
|
use crate::config::AppConfig;
|
||||||
use crate::error::UrlGenerationError;
|
use crate::error::UrlGenerationError;
|
||||||
|
@ -22,7 +22,7 @@ pub(crate) struct HttpRequestInner {
|
||||||
pub(crate) head: Message<RequestHead>,
|
pub(crate) head: Message<RequestHead>,
|
||||||
pub(crate) path: Path<Url>,
|
pub(crate) path: Path<Url>,
|
||||||
pub(crate) payload: Payload,
|
pub(crate) payload: Payload,
|
||||||
pub(crate) app_data: TinyVec<[Rc<Extensions>; 4]>,
|
pub(crate) app_data: SmallVec<[Rc<Extensions>; 4]>,
|
||||||
rmap: Rc<ResourceMap>,
|
rmap: Rc<ResourceMap>,
|
||||||
config: AppConfig,
|
config: AppConfig,
|
||||||
pool: &'static HttpRequestPool,
|
pool: &'static HttpRequestPool,
|
||||||
|
@ -39,7 +39,7 @@ impl HttpRequest {
|
||||||
app_data: Rc<Extensions>,
|
app_data: Rc<Extensions>,
|
||||||
pool: &'static HttpRequestPool,
|
pool: &'static HttpRequestPool,
|
||||||
) -> HttpRequest {
|
) -> HttpRequest {
|
||||||
let mut data = TinyVec::<[Rc<Extensions>; 4]>::new();
|
let mut data = SmallVec::<[Rc<Extensions>; 4]>::new();
|
||||||
data.push(app_data);
|
data.push(app_data);
|
||||||
|
|
||||||
HttpRequest(Rc::new(HttpRequestInner {
|
HttpRequest(Rc::new(HttpRequestInner {
|
||||||
|
@ -277,10 +277,16 @@ impl HttpMessage for HttpRequest {
|
||||||
impl Drop for HttpRequest {
|
impl Drop for HttpRequest {
|
||||||
fn drop(&mut self) {
|
fn drop(&mut self) {
|
||||||
// if possible, contribute to current worker's HttpRequest allocation pool
|
// if possible, contribute to current worker's HttpRequest allocation pool
|
||||||
if Rc::strong_count(&self.0) == 1 {
|
|
||||||
let v = &mut self.0.pool.0.borrow_mut();
|
// This relies on no Weak<HttpRequestInner> exists anywhere.(There is none)
|
||||||
|
if let Some(inner) = Rc::get_mut(&mut self.0) {
|
||||||
|
let v = &mut inner.pool.0.borrow_mut();
|
||||||
if v.len() < 128 {
|
if v.len() < 128 {
|
||||||
self.extensions_mut().clear();
|
// clear additional app_data and keep the root one for reuse.
|
||||||
|
inner.app_data.truncate(1);
|
||||||
|
// inner is borrowed mut here. get head's Extension mutably
|
||||||
|
// to reduce borrow check
|
||||||
|
inner.head.extensions.get_mut().clear();
|
||||||
v.push(self.0.clone());
|
v.push(self.0.clone());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue