Skip to content

Commit

Permalink
Remove #[inline] from large functions (#655)
Browse files Browse the repository at this point in the history
  • Loading branch information
astoring authored Jan 19, 2024
1 parent 0e526ad commit a6350e8
Show file tree
Hide file tree
Showing 39 changed files with 0 additions and 77 deletions.
2 changes: 0 additions & 2 deletions crates/compression/src/encoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,6 @@ pub(super) enum Encoder {
}

impl Encoder {
#[allow(unused_variables)]
pub(super) fn new(algo: CompressionAlgo, level: CompressionLevel) -> Self {
match algo {
#[cfg(feature = "brotli")]
Expand All @@ -118,7 +117,6 @@ impl Encoder {
CompressionAlgo::Zstd => Self::Zstd(level.into_zstd()),
}
}
#[inline]
pub(super) fn take(&mut self) -> IoResult<Bytes> {
match *self {
#[cfg(feature = "brotli")]
Expand Down
1 change: 0 additions & 1 deletion crates/compression/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,6 @@ pub struct Compression {
}

impl Default for Compression {
#[inline]
fn default() -> Self {
#[allow(unused_mut)]
let mut algos = IndexMap::new();
Expand Down
4 changes: 0 additions & 4 deletions crates/compression/src/stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,13 @@ impl EncodeStream<BoxStream<'static, Result<Bytes, BoxedError>>> {
}
}
impl EncodeStream<BoxStream<'static, Result<BytesFrame, BoxedError>>> {
#[inline]
fn poll_chunk(&mut self, cx: &mut Context<'_>) -> Poll<Option<IoResult<Bytes>>> {
Stream::poll_next(Pin::new(&mut self.body), cx)
.map_ok(|f| f.into_data().unwrap_or_default())
.map_err(|e| IoError::new(ErrorKind::Other, e))
}
}
impl EncodeStream<HyperBody> {
#[inline]
fn poll_chunk(&mut self, cx: &mut Context<'_>) -> Poll<Option<IoResult<Bytes>>> {
match ready!(Body::poll_frame(Pin::new(&mut self.body), cx)) {
Some(Ok(frame)) => Poll::Ready(frame.into_data().map(Ok).ok()),
Expand All @@ -59,7 +57,6 @@ impl EncodeStream<HyperBody> {
}
}
impl EncodeStream<Option<Bytes>> {
#[inline]
fn poll_chunk(&mut self, _cx: &mut Context<'_>) -> Poll<Option<IoResult<Bytes>>> {
if let Some(body) = Pin::new(&mut self.body).take() {
Poll::Ready(Some(Ok(body)))
Expand All @@ -69,7 +66,6 @@ impl EncodeStream<Option<Bytes>> {
}
}
impl EncodeStream<VecDeque<Bytes>> {
#[inline]
fn poll_chunk(&mut self, _cx: &mut Context<'_>) -> Poll<Option<IoResult<Bytes>>> {
if let Some(body) = Pin::new(&mut self.body).pop_front() {
Poll::Ready(Some(Ok(body)))
Expand Down
3 changes: 0 additions & 3 deletions crates/core/src/catcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,6 @@ impl Handler for DefaultGoal {
}
}

#[inline]
fn status_error_html(code: StatusCode, name: &str, brief: &str, cause: Option<&str>, footer: Option<&str>) -> String {
format!(
r#"<!DOCTYPE html>
Expand Down Expand Up @@ -231,7 +230,6 @@ fn status_error_json(code: StatusCode, name: &str, brief: &str, cause: Option<&s
serde_json::to_string(&data).unwrap()
}

#[inline]
fn status_error_plain(code: StatusCode, name: &str, brief: &str, cause: Option<&str>) -> String {
format!(
"code: {}\n\nname: {}\n\nbrief: {}\n\ncause: {}",
Expand All @@ -242,7 +240,6 @@ fn status_error_plain(code: StatusCode, name: &str, brief: &str, cause: Option<&
)
}

#[inline]
fn status_error_xml(code: StatusCode, name: &str, brief: &str, cause: Option<&str>) -> String {
#[derive(Serialize)]
struct Data<'a> {
Expand Down
6 changes: 0 additions & 6 deletions crates/core/src/conn/acme/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,6 @@ where
{
type Error = IoError;

#[inline]
async fn read_key(&self, directory_name: &str, domains: &[String]) -> Result<Option<Vec<u8>>, Self::Error> {
let mut path = self.as_ref().to_path_buf();
path.push(format!(
Expand All @@ -124,7 +123,6 @@ where
},
}
}
#[inline]
async fn write_key(&self, directory_name: &str, domains: &[String], data: &[u8]) -> Result<(), Self::Error> {
let mut path = self.as_ref().to_path_buf();
create_dir_all(&path).await?;
Expand All @@ -137,7 +135,6 @@ where
write_data(path, data).await
}

#[inline]
async fn read_cert(&self, directory_name: &str, domains: &[String]) -> Result<Option<Vec<u8>>, Self::Error> {
let mut path = self.as_ref().to_path_buf();
path.push(format!(
Expand All @@ -154,7 +151,6 @@ where
},
}
}
#[inline]
async fn write_cert(&self, directory_name: &str, domains: &[String], data: &[u8]) -> Result<(), Self::Error> {
let mut path = self.as_ref().to_path_buf();
create_dir_all(&path).await?;
Expand All @@ -167,7 +163,6 @@ where
write_data(path, data).await
}
}
#[inline]
async fn write_data(file_path: impl AsRef<Path> + Send, data: impl AsRef<[u8]> + Send) -> IoResult<()> {
let mut file = OpenOptions::new();
file.write(true).create(true).truncate(true);
Expand All @@ -180,7 +175,6 @@ async fn write_data(file_path: impl AsRef<Path> + Send, data: impl AsRef<[u8]> +
Ok(())
}

#[inline]
fn file_hash_part(data: &[String]) -> String {
let mut ctx = Context::new(&SHA256);
for el in data {
Expand Down
5 changes: 0 additions & 5 deletions crates/core/src/conn/acme/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ pub(crate) struct AcmeClient {
}

impl AcmeClient {
#[inline]
pub(crate) async fn new(directory_url: &str, key_pair: Arc<KeyPair>, contacts: Vec<String>) -> crate::Result<Self> {
let https = HttpsConnectorBuilder::new()
.with_native_roots()
Expand Down Expand Up @@ -114,7 +113,6 @@ impl AcmeClient {
Ok(res)
}

#[inline]
pub(crate) async fn fetch_authorization(&self, auth_url: &str) -> crate::Result<FetchAuthorizationResponse> {
tracing::debug!(auth_url, "fetch authorization");

Expand All @@ -138,7 +136,6 @@ impl AcmeClient {
Ok(res)
}

#[inline]
pub(crate) async fn trigger_challenge(
&self,
domain: &str,
Expand Down Expand Up @@ -166,7 +163,6 @@ impl AcmeClient {
Ok(())
}

#[inline]
pub(crate) async fn send_csr(&self, url: &str, csr: &[u8]) -> crate::Result<NewOrderResponse> {
tracing::debug!(url, "send certificate request");

Expand All @@ -190,7 +186,6 @@ impl AcmeClient {
.await
}

#[inline]
pub(crate) async fn obtain_certificate(&self, url: &str) -> crate::Result<Bytes> {
tracing::debug!(url, "send certificate request");

Expand Down
2 changes: 0 additions & 2 deletions crates/core/src/conn/acme/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ impl AcmeConfig {
}

impl Debug for AcmeConfig {
#[inline]
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
f.debug_struct("AcmeConfig")
.field("directory_name", &self.directory_name)
Expand Down Expand Up @@ -149,7 +148,6 @@ impl AcmeConfigBuilder {
}

/// Consumes this builder and returns a [`AcmeConfig`] object.
#[inline]
pub fn build(self) -> IoResult<AcmeConfig> {
self.directory_url
.parse::<Uri>()
Expand Down
1 change: 0 additions & 1 deletion crates/core/src/conn/acme/issuer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,6 @@ pub(crate) async fn issue_cert(
Ok(())
}

#[inline]
fn gen_acme_cert(domain: &str, acme_hash: &[u8]) -> crate::Result<CertifiedKey> {
let mut params = CertificateParams::new(vec![domain.to_string()]);
params.alg = &PKCS_ECDSA_P256_SHA256;
Expand Down
3 changes: 0 additions & 3 deletions crates/core/src/conn/acme/jose.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ struct Protected<'a> {
}

impl<'a> Protected<'a> {
#[inline]
fn base64(jwk: Option<Jwk>, kid: Option<&'a str>, nonce: &'a str, url: &'a str) -> IoResult<String> {
let protected = Self {
alg: "ES256",
Expand Down Expand Up @@ -63,7 +62,6 @@ impl Jwk {
}
}

#[inline]
fn thumb_sha256_base64(&self) -> IoResult<String> {
#[derive(Serialize)]
struct JwkThumb<'a> {
Expand Down Expand Up @@ -144,7 +142,6 @@ pub(crate) async fn request(
}
Ok(res)
}
#[inline]
pub(crate) async fn request_json<T, R>(
cli: &HyperClient,
key_pair: &KeyPair,
Expand Down
1 change: 0 additions & 1 deletion crates/core/src/conn/acme/listener.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,6 @@ impl<T> AcmeListener<T> {
}

/// Create an handler for HTTP-01 challenge
#[inline]
pub fn http01_challege(self, router: &mut Router) -> Self {
let config_builder = self.config_builder.http01_challege();
if let Some(keys_for_http01) = &config_builder.keys_for_http01 {
Expand Down
1 change: 0 additions & 1 deletion crates/core/src/conn/acme/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,6 @@ pub(crate) struct Http01Handler {

#[async_trait]
impl Handler for Http01Handler {
#[inline]
async fn handle(&self, req: &mut Request, _depot: &mut Depot, res: &mut Response, _ctrl: &mut FlowCtrl) {
if let Some(token) = req.params().get("token") {
let keys = self.keys.read();
Expand Down
2 changes: 0 additions & 2 deletions crates/core/src/conn/acme/resolver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ impl ResolveServerCert {
}

impl ResolvesServerCert for ResolveServerCert {
#[inline]
fn resolve(&self, client_hello: ClientHello) -> Option<Arc<CertifiedKey>> {
if client_hello
.alpn()
Expand Down Expand Up @@ -80,7 +79,6 @@ pub(crate) struct ResolveServerCertOld {
}
#[cfg(feature = "quinn")]
impl ResolvesServerCertOld for ResolveServerCertOld {
#[inline]
fn resolve(&self, client_hello: OldClientHello) -> Option<Arc<CertifiedKeyOld>> {
if client_hello
.alpn()
Expand Down
1 change: 0 additions & 1 deletion crates/core/src/conn/native_tls/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ impl NativeTlsConfig {
}

/// Build identity
#[inline]
pub fn build_identity(mut self) -> IoResult<Identity> {
if self.pkcs12.is_empty() {
if let Some(path) = &self.pkcs12_path {
Expand Down
1 change: 0 additions & 1 deletion crates/core/src/conn/openssl/listener.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,6 @@ where
&self.holdings
}

#[inline]
async fn accept(&mut self) -> IoResult<Accepted<Self::Conn>> {
let config = {
let mut config = None;
Expand Down
1 change: 0 additions & 1 deletion crates/core/src/conn/quinn/listener.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,6 @@ where
&self.holdings
}

#[inline]
async fn accept(&mut self) -> IoResult<Accepted<Self::Conn>> {
let config = {
let mut config = None;
Expand Down
2 changes: 0 additions & 2 deletions crates/core/src/conn/rustls/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,6 @@ impl RustlsConfig {
///
/// Anonymous and authenticated clients will be accepted. If no trust anchor is provided by any
/// of the `client_auth_` methods, then client authentication is disabled by default.
#[inline]
pub fn client_auth_optional_path(mut self, path: impl AsRef<Path>) -> IoResult<Self> {
let mut data = vec![];
let mut file = File::open(path)?;
Expand All @@ -229,7 +228,6 @@ impl RustlsConfig {
///
/// Only authenticated clients will be accepted. If no trust anchor is provided by any of the
/// `client_auth_` methods, then client authentication is disabled by default.
#[inline]
pub fn client_auth_required_path(mut self, path: impl AsRef<Path>) -> IoResult<Self> {
let mut data = vec![];
let mut file = File::open(path)?;
Expand Down
1 change: 0 additions & 1 deletion crates/core/src/conn/rustls/listener.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,6 @@ where
&self.holdings
}

#[inline]
async fn accept(&mut self) -> IoResult<Accepted<Self::Conn>> {
let config = {
let mut config = None;
Expand Down
2 changes: 0 additions & 2 deletions crates/core/src/depot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,6 @@ impl Depot {
///
/// Returns `Err(None)` if value is not present in depot.
/// Returns `Err(Some(Box<dyn Any + Send + Sync>))` if value is present in depot but downcast failed.
#[inline]
pub fn get_mut<V: Any + Send + Sync>(
&mut self,
key: &str,
Expand Down Expand Up @@ -176,7 +175,6 @@ impl Depot {
}

impl fmt::Debug for Depot {
#[inline]
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
f.debug_struct("Depot").field("keys", &self.map.keys()).finish()
}
Expand Down
1 change: 0 additions & 1 deletion crates/core/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ impl Error {
}
}
impl Display for Error {
#[inline]
fn fmt(&self, f: &mut Formatter) -> fmt::Result {
match self {
Self::Hyper(e) => Display::fmt(e, f),
Expand Down
2 changes: 0 additions & 2 deletions crates/core/src/http/errors/status_error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,6 @@ impl StatusError {
impl StdError for StatusError {}

impl Display for StatusError {
#[inline]
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
write!(f, "code: {}", self.code)?;
write!(f, "name: {}", self.name)?;
Expand All @@ -118,7 +117,6 @@ impl Display for StatusError {
}
impl StatusError {
/// Create new `StatusError` with code. If code is not error, it will be `None`.
#[inline]
pub fn from_code(code: StatusCode) -> Option<StatusError> {
match code {
StatusCode::BAD_REQUEST => Some(StatusError::bad_request()),
Expand Down
1 change: 0 additions & 1 deletion crates/core/src/http/form.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,6 @@ impl FilePart {

/// Create a new temporary FilePart (when created this way, the file will be
/// deleted once the FilePart object goes out of scope).
#[inline]
pub async fn create(field: &mut Field<'_>) -> Result<FilePart, ParseError> {
// Setup a file to capture the contents.
let mut path = tokio::task::spawn_blocking(|| Builder::new().prefix("salvo_http_multipart").tempdir())
Expand Down
4 changes: 0 additions & 4 deletions crates/core/src/http/request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,6 @@ impl Request {

/// Strip the request to [`hyper::Request`].
#[doc(hidden)]
#[inline]
pub fn strip_to_hyper<QB>(&mut self) -> Result<hyper::Request<QB>, crate::Error>
where
QB: TryFrom<ReqBody>,
Expand All @@ -202,7 +201,6 @@ impl Request {

/// Merge data from [`hyper::Request`].
#[doc(hidden)]
#[inline]
pub fn merge_hyper(&mut self, hyper_req: hyper::Request<ReqBody>) {
let (
http::request::Parts {
Expand Down Expand Up @@ -448,7 +446,6 @@ impl Request {
matches!((self.method(), protocol), (&Method::CONNECT, Some(p)) if p == &salvo_http3::ext::Protocol::WEB_TRANSPORT)
}

#[inline]
/// Try to get a WebTransport session from the request.
pub async fn web_transport_mut(&mut self) -> Result<&mut crate::proto::WebTransportSession<salvo_http3::http3_quinn::Connection, Bytes>, crate::Error> {
if self.is_wt_connect() {
Expand Down Expand Up @@ -832,7 +829,6 @@ impl Request {
}

/// Parse json body or form body as type `T` from request with max size.
#[inline]
pub async fn parse_body_with_max_size<'de, T>(&'de mut self, max_size: usize) -> Result<T, ParseError>
where
T: Deserialize<'de>,
Expand Down
3 changes: 0 additions & 3 deletions crates/core/src/http/response.rs
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,6 @@ impl Response {
/// Attempts to send a file. If file not exists, not found error will occur.
///
/// If you want more settings, you can use `NamedFile::builder` to create a new [`NamedFileBuilder`](crate::fs::NamedFileBuilder).
#[inline]
pub async fn send_file<P>(&mut self, path: P, req_headers: &HeaderMap)
where
P: Into<PathBuf> + Send,
Expand All @@ -407,7 +406,6 @@ impl Response {
}

/// Write bytes data to body. If body is none, a new `ResBody` will created.
#[inline]
pub fn write_body(&mut self, data: impl Into<Bytes>) -> crate::Result<()> {
match self.body_mut() {
ResBody::None => {
Expand Down Expand Up @@ -473,7 +471,6 @@ impl Response {
}

impl fmt::Debug for Response {
#[inline]
fn fmt(&self, f: &mut Formatter) -> fmt::Result {
f.debug_struct("Response")
.field("status_code", &self.status_code)
Expand Down
Loading

0 comments on commit a6350e8

Please sign in to comment.