Avoid &format("...")
calls in error message code.
Error message all end up passing into a function as an `impl Into<{D,Subd}iagnosticMessage>`. If an error message is creatd as `&format("...")` that means we allocate a string (in the `format!` call), then take a reference, and then clone (allocating again) the reference to produce the `{D,Subd}iagnosticMessage`, which is silly. This commit removes the leading `&` from a lot of these cases. This means the original `String` is moved into the `{D,Subd}iagnosticMessage`, avoiding the double allocations. This requires changing some function argument types from `&str` to `String` (when all arguments are `String`) or `impl Into<{D,Subd}iagnosticMessage>` (when some arguments are `String` and some are `&str`).
This commit is contained in:
parent
87a2bc027c
commit
01e33a3600
37 changed files with 139 additions and 133 deletions
|
@ -192,11 +192,11 @@ fn init_logging() {
|
|||
Ok("auto") | Err(VarError::NotPresent) => io::stdout().is_terminal(),
|
||||
Ok(value) => early_error(
|
||||
ErrorOutputType::default(),
|
||||
&format!("invalid log color value '{}': expected one of always, never, or auto", value),
|
||||
format!("invalid log color value '{}': expected one of always, never, or auto", value),
|
||||
),
|
||||
Err(VarError::NotUnicode(value)) => early_error(
|
||||
ErrorOutputType::default(),
|
||||
&format!(
|
||||
format!(
|
||||
"invalid log color value '{}': expected one of always, never, or auto",
|
||||
value.to_string_lossy()
|
||||
),
|
||||
|
@ -228,7 +228,7 @@ fn get_args() -> Option<Vec<String>> {
|
|||
.map_err(|arg| {
|
||||
early_warn(
|
||||
ErrorOutputType::default(),
|
||||
&format!("Argument {} is not valid Unicode: {:?}", i, arg),
|
||||
format!("Argument {} is not valid Unicode: {:?}", i, arg),
|
||||
);
|
||||
})
|
||||
.ok()
|
||||
|
@ -721,7 +721,7 @@ fn main_args(at_args: &[String]) -> MainResult {
|
|||
let matches = match options.parse(&args[1..]) {
|
||||
Ok(m) => m,
|
||||
Err(err) => {
|
||||
early_error(ErrorOutputType::default(), &err.to_string());
|
||||
early_error(ErrorOutputType::default(), err.to_string());
|
||||
}
|
||||
};
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue