Skip to content

Commit

Permalink
chore: reduce some allocations in several modules (#337)
Browse files Browse the repository at this point in the history
  • Loading branch information
joseluisq committed Apr 12, 2024
1 parent c04357e commit e569a71
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 16 deletions.
2 changes: 1 addition & 1 deletion src/custom_headers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ pub fn append_headers(
_ => uri_path,
};

for headers_entry in headers_vec.iter() {
for headers_entry in headers_vec {
// Match header glob pattern against request uri
if headers_entry.source.is_match(uri_path) {
// Add/update headers if uri matches
Expand Down
10 changes: 4 additions & 6 deletions src/error_page.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,9 @@ pub fn error_response(
// Extra check for 404 status code and its HTML content
if status_code == &StatusCode::NOT_FOUND {
if page404.is_file() {
page_content = String::from_utf8_lossy(&helpers::read_bytes_default(page404))
.to_string()
String::from_utf8_lossy(&helpers::read_bytes_default(page404))
.trim()
.to_owned();
.clone_into(&mut page_content);
} else {
tracing::debug!(
"page404 file path not found or not a regular file: {}",
Expand All @@ -76,10 +75,9 @@ pub fn error_response(
| &StatusCode::LOOP_DETECTED => {
// HTML content check for status codes 50x
if page50x.is_file() {
page_content = String::from_utf8_lossy(&helpers::read_bytes_default(page50x))
.to_string()
String::from_utf8_lossy(&helpers::read_bytes_default(page50x))
.trim()
.to_owned();
.clone_into(&mut page_content);
} else {
tracing::debug!(
"page50x file path not found or not a regular file: {}",
Expand Down
5 changes: 2 additions & 3 deletions src/maintenance_mode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,9 @@ pub fn get_response(

let mut body_content = String::new();
if file_path.is_file() {
body_content = String::from_utf8_lossy(&helpers::read_bytes_default(file_path))
.to_string()
String::from_utf8_lossy(&helpers::read_bytes_default(file_path))
.trim()
.to_owned();
.clone_into(&mut body_content);
} else {
tracing::debug!(
"maintenance mode file path not found or not a regular file, using a default message"
Expand Down
2 changes: 1 addition & 1 deletion src/redirects.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ pub fn get_redirection<'a>(
redirects_opts: Option<&'a [Redirects]>,
) -> Option<&'a Redirects> {
if let Some(redirects_vec) = redirects_opts {
for redirect_entry in redirects_vec.iter() {
for redirect_entry in redirects_vec {
// Match `host` redirect against `uri_host` if specified
if let Some(host) = &redirect_entry.host {
tracing::debug!(
Expand Down
2 changes: 1 addition & 1 deletion src/rewrites.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ pub fn rewrite_uri_path<'a>(
rewrites_opts: Option<&'a [Rewrites]>,
) -> Option<&'a Rewrites> {
if let Some(rewrites_vec) = rewrites_opts {
for rewrites_entry in rewrites_vec.iter() {
for rewrites_entry in rewrites_vec {
// Match source glob pattern against request uri path
if rewrites_entry.source.is_match(uri_path) {
return Some(rewrites_entry);
Expand Down
8 changes: 4 additions & 4 deletions src/settings/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -245,13 +245,13 @@ impl Settings {
security_headers = v
}
if let Some(ref v) = general.cors_allow_origins {
cors_allow_origins = v.to_owned()
v.clone_into(&mut cors_allow_origins)
}
if let Some(ref v) = general.cors_allow_headers {
cors_allow_headers = v.to_owned()
v.clone_into(&mut cors_allow_headers)
}
if let Some(ref v) = general.cors_expose_headers {
cors_expose_headers = v.to_owned()
v.clone_into(&mut cors_expose_headers)
}
#[cfg(feature = "directory-listing")]
if let Some(v) = general.directory_listing {
Expand All @@ -267,7 +267,7 @@ impl Settings {
}
#[cfg(feature = "basic-auth")]
if let Some(ref v) = general.basic_auth {
basic_auth = v.to_owned()
v.clone_into(&mut basic_auth)
}
if let Some(v) = general.fd {
fd = Some(v)
Expand Down

0 comments on commit e569a71

Please sign in to comment.