Skip to content

Commit

Permalink
write! perf optimization - use write_str (#1182)
Browse files Browse the repository at this point in the history
  • Loading branch information
nyurik authored Feb 7, 2024
1 parent 04e53a7 commit 0b4e3f9
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 13 deletions.
18 changes: 9 additions & 9 deletions martin-tile-utils/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,14 +75,14 @@ impl Format {

impl Display for Format {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match *self {
Self::Gif => write!(f, "gif"),
Self::Jpeg => write!(f, "jpeg"),
Self::Json => write!(f, "json"),
Self::Mvt => write!(f, "mvt"),
Self::Png => write!(f, "png"),
Self::Webp => write!(f, "webp"),
}
f.write_str(match *self {
Self::Gif => "gif",
Self::Jpeg => "jpeg",
Self::Json => "json",
Self::Mvt => "mvt",
Self::Png => "png",
Self::Webp => "webp",
})
}
}

Expand Down Expand Up @@ -194,7 +194,7 @@ impl Display for TileInfo {
if let Some(encoding) = self.encoding.content_encoding() {
write!(f, "; encoding={encoding}")?;
} else if self.encoding != Encoding::Uncompressed {
write!(f, "; uncompressed")?;
f.write_str("; uncompressed")?;
}
Ok(())
}
Expand Down
4 changes: 2 additions & 2 deletions martin/src/bin/martin-cp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -253,9 +253,9 @@ impl Display for Progress {

let left = self.total - done;
if left == 0 {
write!(f, " | done")
f.write_str(" | done")
} else if done == 0 {
write!(f, " | ??? left")
f.write_str(" | ??? left")
} else {
let left = Duration::from_secs_f32(elapsed_s * left as f32 / done as f32);
write!(f, " | {left:.0?} left")
Expand Down
4 changes: 2 additions & 2 deletions martin/src/pg/query_functions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,13 @@ pub async fn query_available_function(pool: &PgPool) -> PgResult<SqlFuncInfoMapM
query.push('(');
for (idx, (_name, typ)) in zip(input_names.iter(), input_types.iter()).enumerate() {
if idx > 0 {
write!(query, ", ").unwrap();
query.push_str(", ");
}
// This could also be done as "{name} => ${index}::{typ}"
// where the name must be passed through escape_identifier
write!(query, "${index}::{typ}", index = idx + 1).unwrap();
}
write!(query, ")").unwrap();
query.push(')');

// TODO: Rewrite as a if-let chain: if Some(names) = output_record_names && output_type == "record" { ... }
let ret_inf = if let (Some(names), "record") = (output_record_names, output_type.as_str()) {
Expand Down

0 comments on commit 0b4e3f9

Please sign in to comment.