Skip to content

Commit

Permalink
replace String::from_utf8() with std::str::from_utf8()
Browse files Browse the repository at this point in the history
allocation should be avoided when possible since it's relatively slow
  • Loading branch information
abysssol authored and cole-h committed Aug 8, 2024
1 parent f362b08 commit 29bae01
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 8 deletions.
6 changes: 3 additions & 3 deletions ofborg/src/tasks/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ impl notifyworker::SimpleNotifyWorker for BuildWorker {
match buildjob::from(body) {
Ok(job) => Ok(job),
Err(err) => {
error!("{:?}", String::from_utf8(body.to_vec()));
error!("{:?}", std::str::from_utf8(body).unwrap_or("<not utf8>"));
panic!("{err:?}");
}
}
Expand Down Expand Up @@ -453,8 +453,8 @@ mod tests {
actions
.position(|job| match job {
worker::Action::Publish(ref body) => {
let content = String::from_utf8(body.content.clone()).unwrap();
let text = strip_escaped_ansi(&content);
let content = std::str::from_utf8(&body.content).unwrap();
let text = strip_escaped_ansi(content);
eprintln!("{text}");
if text.contains(text_to_match) {
println!(" ok");
Expand Down
4 changes: 2 additions & 2 deletions ofborg/src/tasks/evaluate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ impl<E: stats::SysEvents + 'static> worker::SimpleWorker for EvaluationWorker<E>
Err(err) => {
self.events.notify(Event::JobDecodeFailure);
error!(
"Failed to decode message: {:?}, Err: {err:?}",
String::from_utf8(body.to_vec())
"Failed to decode message: {}, Err: {err:?}",
std::str::from_utf8(body).unwrap_or("<message not utf8>")
);
Err("Failed to decode message".to_owned())
}
Expand Down
2 changes: 1 addition & 1 deletion ofborg/src/tasks/evaluationfilter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ impl worker::SimpleWorker for EvaluationFilterWorker {
Ok(event) => Ok(event),
Err(err) => Err(format!(
"Failed to deserialize job {err:?}: {:?}",
String::from_utf8(body.to_vec())
std::str::from_utf8(body).unwrap_or("<job not utf8>")
)),
}
}
Expand Down
2 changes: 1 addition & 1 deletion ofborg/src/tasks/githubcommentfilter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ impl worker::SimpleWorker for GitHubCommentWorker {
Err(err) => {
error!(
"Failed to deserialize IsssueComment: {:?}",
String::from_utf8(body.to_vec())
std::str::from_utf8(body).unwrap_or("<not utf8>")
);
panic!("{err:?}");
}
Expand Down
2 changes: 1 addition & 1 deletion ofborg/src/tasks/statscollector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ impl<E: stats::SysEvents + 'static> worker::SimpleWorker for StatCollectorWorker
self.events.notify(stats::Event::StatCollectorBogusEvent);
error!(
"Failed to decode message: {:?}, Err: {err:?}",
String::from_utf8(body.to_vec())
std::str::from_utf8(body).unwrap_or("<message not utf8>")
);
Err("Failed to decode message".to_owned())
}
Expand Down

0 comments on commit 29bae01

Please sign in to comment.