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 {
|
||||
state: State::A {
|
||||
fut: self.0 .0.call(req),
|
||||
b: Some(self.0.clone()),
|
||||
b: self.0.clone(),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
|
@ -84,7 +84,7 @@ pin_project! {
|
|||
A {
|
||||
#[pin]
|
||||
fut: A::Future,
|
||||
b: Option<Rc<(A, B)>>,
|
||||
b: Rc<(A, B)>,
|
||||
},
|
||||
B {
|
||||
#[pin]
|
||||
|
|
@ -101,17 +101,17 @@ where
|
|||
type Output = Result<B::Response, A::Error>;
|
||||
|
||||
fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
|
||||
loop {
|
||||
let mut this = self.as_mut().project();
|
||||
|
||||
match this.state.as_mut().project() {
|
||||
StateProj::A { fut, b } => {
|
||||
let res = ready!(fut.poll(cx))?;
|
||||
let b = b.take().unwrap();
|
||||
let fut = b.1.call(res);
|
||||
this.state.set(State::B { fut });
|
||||
self.poll(cx)
|
||||
}
|
||||
StateProj::B { fut } => fut.poll(cx),
|
||||
StateProj::B { fut } => return fut.poll(cx),
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -209,24 +209,26 @@ where
|
|||
type Output = Result<S, SF::InitError>;
|
||||
|
||||
fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
|
||||
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 });
|
||||
self.poll(cx)
|
||||
}
|
||||
StateProj::B { svc } => {
|
||||
ready!(svc.poll_ready(cx))?;
|
||||
{
|
||||
|
||||
let fut = {
|
||||
let (_, f) = &**this.store;
|
||||
let fut = f(this.cfg.take().unwrap(), svc);
|
||||
f(this.cfg.take().unwrap(), svc)
|
||||
};
|
||||
|
||||
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 {
|
||||
state: State::A {
|
||||
fut: self.0 .0.call(req),
|
||||
b: Some(self.0.clone()),
|
||||
b: self.0.clone(),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
|
@ -81,7 +81,7 @@ pin_project! {
|
|||
A: Service<Req>,
|
||||
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 },
|
||||
}
|
||||
}
|
||||
|
|
@ -94,17 +94,17 @@ where
|
|||
type Output = Result<B::Response, B::Error>;
|
||||
|
||||
fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
|
||||
loop {
|
||||
let mut this = self.as_mut().project();
|
||||
|
||||
match this.state.as_mut().project() {
|
||||
StateProj::A { fut, b } => {
|
||||
let res = ready!(fut.poll(cx));
|
||||
let b = b.take().unwrap();
|
||||
let fut = b.1.call(res);
|
||||
this.state.set(State::B { fut });
|
||||
self.poll(cx)
|
||||
}
|
||||
StateProj::B { fut } => fut.poll(cx),
|
||||
StateProj::B { fut } => return fut.poll(cx),
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -205,6 +205,7 @@ where
|
|||
type Output = Result<T::Transform, T::InitError>;
|
||||
|
||||
fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
|
||||
loop {
|
||||
let mut this = self.as_mut().project();
|
||||
|
||||
match this.state.as_mut().project() {
|
||||
|
|
@ -212,9 +213,9 @@ where
|
|||
let srv = ready!(fut.poll(cx))?;
|
||||
let fut = this.store.0.new_transform(srv);
|
||||
this.state.set(ApplyTransformFutureState::B { fut });
|
||||
self.poll(cx)
|
||||
}
|
||||
ApplyTransformFutureStateProj::B { fut } => fut.poll(cx),
|
||||
ApplyTransformFutureStateProj::B { fut } => return fut.poll(cx),
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue