mirror of https://github.com/fafhrd91/actix-net
perf: eliminate recursive call and unnecessary Option (#814)
This commit is contained in:
parent
c347906c78
commit
dd205fd155
|
|
@ -57,7 +57,7 @@ where
|
||||||
AndThenServiceResponse {
|
AndThenServiceResponse {
|
||||||
state: State::A {
|
state: State::A {
|
||||||
fut: self.0 .0.call(req),
|
fut: self.0 .0.call(req),
|
||||||
b: Some(self.0.clone()),
|
b: self.0.clone(),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -84,7 +84,7 @@ pin_project! {
|
||||||
A {
|
A {
|
||||||
#[pin]
|
#[pin]
|
||||||
fut: A::Future,
|
fut: A::Future,
|
||||||
b: Option<Rc<(A, B)>>,
|
b: Rc<(A, B)>,
|
||||||
},
|
},
|
||||||
B {
|
B {
|
||||||
#[pin]
|
#[pin]
|
||||||
|
|
@ -101,17 +101,17 @@ where
|
||||||
type Output = Result<B::Response, A::Error>;
|
type Output = Result<B::Response, A::Error>;
|
||||||
|
|
||||||
fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
|
fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
|
||||||
let mut this = self.as_mut().project();
|
loop {
|
||||||
|
let mut this = self.as_mut().project();
|
||||||
|
|
||||||
match this.state.as_mut().project() {
|
match this.state.as_mut().project() {
|
||||||
StateProj::A { fut, b } => {
|
StateProj::A { fut, b } => {
|
||||||
let res = ready!(fut.poll(cx))?;
|
let res = ready!(fut.poll(cx))?;
|
||||||
let b = b.take().unwrap();
|
let fut = b.1.call(res);
|
||||||
let fut = b.1.call(res);
|
this.state.set(State::B { fut });
|
||||||
this.state.set(State::B { fut });
|
}
|
||||||
self.poll(cx)
|
StateProj::B { fut } => return fut.poll(cx),
|
||||||
}
|
}
|
||||||
StateProj::B { fut } => fut.poll(cx),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -209,24 +209,26 @@ where
|
||||||
type Output = Result<S, SF::InitError>;
|
type Output = Result<S, SF::InitError>;
|
||||||
|
|
||||||
fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
|
fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
|
||||||
let mut this = self.as_mut().project();
|
loop {
|
||||||
|
let mut this = self.as_mut().project();
|
||||||
|
|
||||||
|
match this.state.as_mut().project() {
|
||||||
|
StateProj::A { fut } => {
|
||||||
|
let svc = ready!(fut.poll(cx))?;
|
||||||
|
this.state.set(State::B { svc });
|
||||||
|
}
|
||||||
|
StateProj::B { svc } => {
|
||||||
|
ready!(svc.poll_ready(cx))?;
|
||||||
|
|
||||||
|
let fut = {
|
||||||
|
let (_, f) = &**this.store;
|
||||||
|
f(this.cfg.take().unwrap(), svc)
|
||||||
|
};
|
||||||
|
|
||||||
match this.state.as_mut().project() {
|
|
||||||
StateProj::A { fut } => {
|
|
||||||
let svc = ready!(fut.poll(cx))?;
|
|
||||||
this.state.set(State::B { svc });
|
|
||||||
self.poll(cx)
|
|
||||||
}
|
|
||||||
StateProj::B { svc } => {
|
|
||||||
ready!(svc.poll_ready(cx))?;
|
|
||||||
{
|
|
||||||
let (_, f) = &**this.store;
|
|
||||||
let fut = f(this.cfg.take().unwrap(), svc);
|
|
||||||
this.state.set(State::C { fut });
|
this.state.set(State::C { fut });
|
||||||
}
|
}
|
||||||
self.poll(cx)
|
StateProj::C { fut } => return fut.poll(cx),
|
||||||
}
|
}
|
||||||
StateProj::C { fut } => fut.poll(cx),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -57,7 +57,7 @@ where
|
||||||
ThenServiceResponse {
|
ThenServiceResponse {
|
||||||
state: State::A {
|
state: State::A {
|
||||||
fut: self.0 .0.call(req),
|
fut: self.0 .0.call(req),
|
||||||
b: Some(self.0.clone()),
|
b: self.0.clone(),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -81,7 +81,7 @@ pin_project! {
|
||||||
A: Service<Req>,
|
A: Service<Req>,
|
||||||
B: Service<Result<A::Response, A::Error>>,
|
B: Service<Result<A::Response, A::Error>>,
|
||||||
{
|
{
|
||||||
A { #[pin] fut: A::Future, b: Option<Rc<(A, B)>> },
|
A { #[pin] fut: A::Future, b: Rc<(A, B)> },
|
||||||
B { #[pin] fut: B::Future },
|
B { #[pin] fut: B::Future },
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -94,17 +94,17 @@ where
|
||||||
type Output = Result<B::Response, B::Error>;
|
type Output = Result<B::Response, B::Error>;
|
||||||
|
|
||||||
fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
|
fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
|
||||||
let mut this = self.as_mut().project();
|
loop {
|
||||||
|
let mut this = self.as_mut().project();
|
||||||
|
|
||||||
match this.state.as_mut().project() {
|
match this.state.as_mut().project() {
|
||||||
StateProj::A { fut, b } => {
|
StateProj::A { fut, b } => {
|
||||||
let res = ready!(fut.poll(cx));
|
let res = ready!(fut.poll(cx));
|
||||||
let b = b.take().unwrap();
|
let fut = b.1.call(res);
|
||||||
let fut = b.1.call(res);
|
this.state.set(State::B { fut });
|
||||||
this.state.set(State::B { fut });
|
}
|
||||||
self.poll(cx)
|
StateProj::B { fut } => return fut.poll(cx),
|
||||||
}
|
}
|
||||||
StateProj::B { fut } => fut.poll(cx),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -205,16 +205,17 @@ where
|
||||||
type Output = Result<T::Transform, T::InitError>;
|
type Output = Result<T::Transform, T::InitError>;
|
||||||
|
|
||||||
fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
|
fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
|
||||||
let mut this = self.as_mut().project();
|
loop {
|
||||||
|
let mut this = self.as_mut().project();
|
||||||
|
|
||||||
match this.state.as_mut().project() {
|
match this.state.as_mut().project() {
|
||||||
ApplyTransformFutureStateProj::A { fut } => {
|
ApplyTransformFutureStateProj::A { fut } => {
|
||||||
let srv = ready!(fut.poll(cx))?;
|
let srv = ready!(fut.poll(cx))?;
|
||||||
let fut = this.store.0.new_transform(srv);
|
let fut = this.store.0.new_transform(srv);
|
||||||
this.state.set(ApplyTransformFutureState::B { fut });
|
this.state.set(ApplyTransformFutureState::B { fut });
|
||||||
self.poll(cx)
|
}
|
||||||
|
ApplyTransformFutureStateProj::B { fut } => return fut.poll(cx),
|
||||||
}
|
}
|
||||||
ApplyTransformFutureStateProj::B { fut } => fut.poll(cx),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue