-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Fix and add info messages #1552
Conversation
gavofyork
commented
Jul 6, 2016
- Client handles the enode message to avoid repeats.
- Display journal DB strategy on startup.
} | ||
} | ||
|
||
impl<'a> Applyable for &'a String { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
impl<T: AsRef<str>> Applyable for T { ... }
this will cover all 3 implementations here.
at that point it may be better just to have a free function fn apply_style<T: AsRef<str>>(x: T, c: Style) -> String
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
that results in a useless clone
in the case of String
when you don't have colour enabled.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fair enough, but this code does reallocate borrowed strings when missing color and the end results are also allocated with format!
. To avoid all unnecessary allocations, I suggest
use std::borrow::Cow;
use std::convert::AsRef;
trait Applyable: AsRef<str> {
fn apply(&self, c: Style) -> Cow<str>;
}
impl<T: AsRef<str>> Applyable for T {
fn apply(&self, c: Style) -> Cow<str> {
let s = self.as_ref();
match USE_COLOR.load(Ordering::Relaxed) {
true => Cow::Owned(format!("{}", c.paint(s))),
false => Cow::Borrowed(s),
}
}
}