Skip to content

Commit 7dc3424

Browse files
committed
perf(req/resp): inline frequently called accessor methods
1 parent 7a7730e commit 7dc3424

2 files changed

Lines changed: 27 additions & 21 deletions

File tree

src/client/request.rs

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -72,61 +72,61 @@ impl Request {
7272
}
7373

7474
/// Get the method.
75-
#[inline(always)]
75+
#[inline]
7676
pub fn method(&self) -> &Method {
7777
&self.method
7878
}
7979

8080
/// Get a mutable reference to the method.
81-
#[inline(always)]
81+
#[inline]
8282
pub fn method_mut(&mut self) -> &mut Method {
8383
&mut self.method
8484
}
8585

8686
/// Get the url.
87-
#[inline(always)]
87+
#[inline]
8888
pub fn url(&self) -> &Url {
8989
&self.url
9090
}
9191

9292
/// Get a mutable reference to the url.
93-
#[inline(always)]
93+
#[inline]
9494
pub fn url_mut(&mut self) -> &mut Url {
9595
&mut self.url
9696
}
9797

9898
/// Get the headers.
99-
#[inline(always)]
99+
#[inline]
100100
pub fn headers(&self) -> &HeaderMap {
101101
&self.headers
102102
}
103103

104104
/// Get a mutable reference to the headers.
105-
#[inline(always)]
105+
#[inline]
106106
pub fn headers_mut(&mut self) -> &mut HeaderMap {
107107
&mut self.headers
108108
}
109109

110110
/// Get a mutable reference to the original headers.
111-
#[inline(always)]
111+
#[inline]
112112
pub fn original_headers_mut(&mut self) -> &mut Option<OriginalHeaders> {
113113
RequestConfig::<RequestOriginalHeaders>::get_mut(&mut self.extensions)
114114
}
115115

116116
/// Get a mutable reference to the redirect policy.
117-
#[inline(always)]
117+
#[inline]
118118
pub fn redirect_mut(&mut self) -> &mut Option<redirect::Policy> {
119119
RequestConfig::<RequestRedirectPolicy>::get_mut(&mut self.extensions)
120120
}
121121

122122
/// Get the body.
123-
#[inline(always)]
123+
#[inline]
124124
pub fn body(&self) -> Option<&Body> {
125125
self.body.as_ref()
126126
}
127127

128128
/// Get a mutable reference to the body.
129-
#[inline(always)]
129+
#[inline]
130130
pub fn body_mut(&mut self) -> &mut Option<Body> {
131131
&mut self.body
132132
}
@@ -138,31 +138,31 @@ impl Request {
138138
}
139139

140140
/// Get a mutable reference to the http version.
141-
#[inline(always)]
141+
#[inline]
142142
pub fn version_mut(&mut self) -> &mut Option<Version> {
143143
RequestConfig::<RequestEnforcedHttpVersion>::get_mut(&mut self.extensions)
144144
}
145145

146146
/// Get a mutable reference to the timeout.
147-
#[inline(always)]
147+
#[inline]
148148
pub fn timeout_mut(&mut self) -> &mut Option<Duration> {
149149
RequestConfig::<RequestTotalTimeout>::get_mut(&mut self.extensions)
150150
}
151151

152152
/// Get a mutable reference to the read timeout.
153-
#[inline(always)]
153+
#[inline]
154154
pub fn read_timeout_mut(&mut self) -> &mut Option<Duration> {
155155
RequestConfig::<RequestReadTimeout>::get_mut(&mut self.extensions)
156156
}
157157

158158
/// Get a mutable reference to the tcp connect options.
159-
#[inline(always)]
159+
#[inline]
160160
pub(crate) fn tcp_connect_options_mut(&mut self) -> &mut Option<TcpConnectOptions> {
161161
RequestConfig::<RequestTcpConnectOptions>::get_mut(&mut self.extensions)
162162
}
163163

164164
/// Get a mutable reference to the proxy matcher.
165-
#[inline(always)]
165+
#[inline]
166166
pub(crate) fn proxy_matcher_mut(&mut self) -> &mut Option<ProxyMatcher> {
167167
RequestConfig::<RequestProxyMatcher>::get_mut(&mut self.extensions)
168168
}
@@ -174,30 +174,30 @@ impl Request {
174174
feature = "brotli",
175175
feature = "deflate",
176176
))]
177-
#[inline(always)]
177+
#[inline]
178178
pub(crate) fn accpet_encoding_mut(&mut self) -> &mut Option<AcceptEncoding> {
179179
RequestConfig::<RequestAcceptEncoding>::get_mut(&mut self.extensions)
180180
}
181181

182182
/// Skip client default headers.
183-
#[inline(always)]
183+
#[inline]
184184
pub(crate) fn default_headers_mut(&mut self) -> &mut Option<bool> {
185185
RequestConfig::<RequestSkipDefaultHeaders>::get_mut(&mut self.extensions)
186186
}
187187

188-
#[inline(always)]
188+
#[inline]
189189
pub(crate) fn transport_config_mut(&mut self) -> &mut Option<TransportConfig> {
190190
RequestConfig::<RequestTransportConfig>::get_mut(&mut self.extensions)
191191
}
192192

193193
/// Get the extensions.
194-
#[inline(always)]
194+
#[inline]
195195
pub(crate) fn extensions(&self) -> &Extensions {
196196
&self.extensions
197197
}
198198

199199
/// Get a mutable reference to the extensions.
200-
#[inline(always)]
200+
#[inline]
201201
pub(crate) fn extensions_mut(&mut self) -> &mut Extensions {
202202
&mut self.extensions
203203
}
@@ -325,7 +325,7 @@ impl RequestBuilder {
325325
/// Add a set of Headers to the existing ones on this Request.
326326
///
327327
/// The headers will be merged in to any already set.
328-
pub fn headers(mut self, headers: crate::header::HeaderMap) -> RequestBuilder {
328+
pub fn headers(mut self, headers: HeaderMap) -> RequestBuilder {
329329
if let Ok(ref mut req) = self.request {
330330
crate::util::replace_headers(req.headers_mut(), headers);
331331
}
@@ -349,6 +349,7 @@ impl RequestBuilder {
349349
}
350350

351351
/// Enable HTTP authentication.
352+
#[inline]
352353
pub fn auth<V>(self, value: V) -> RequestBuilder
353354
where
354355
HeaderValue: TryFrom<V>,

src/client/response.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ impl Response {
7272
/// - The response does not include a body (e.g. it responds to a `HEAD` request).
7373
/// - The response is gzipped and automatically decoded (thus changing the actual decoded
7474
/// length).
75+
#[inline]
7576
pub fn content_length(&self) -> Option<u64> {
7677
http_body::Body::size_hint(self.res.body()).exact()
7778
}
@@ -84,6 +85,7 @@ impl Response {
8485
///
8586
/// This requires the optional `cookies` feature to be enabled.
8687
#[cfg(feature = "cookies")]
88+
#[inline]
8789
pub fn cookies(&self) -> impl Iterator<Item = cookie::Cookie> {
8890
cookie::extract_response_cookies(self.res.headers()).filter_map(Result::ok)
8991
}
@@ -103,11 +105,13 @@ impl Response {
103105
}
104106

105107
/// Returns a reference to the associated extensions.
108+
#[inline]
106109
pub fn extensions(&self) -> &http::Extensions {
107110
self.res.extensions()
108111
}
109112

110113
/// Returns a mutable reference to the associated extensions.
114+
#[inline]
111115
pub fn extensions_mut(&mut self) -> &mut http::Extensions {
112116
self.res.extensions_mut()
113117
}
@@ -143,6 +147,7 @@ impl Response {
143147
/// # Ok(())
144148
/// # }
145149
/// ```
150+
#[inline]
146151
pub async fn text(self) -> crate::Result<String> {
147152
#[cfg(feature = "charset")]
148153
{

0 commit comments

Comments
 (0)