Skip to content
This repository has been archived by the owner on Nov 6, 2020. It is now read-only.

Fix and add info messages #1552

Merged
merged 7 commits into from
Jul 6, 2016
Merged

Fix and add info messages #1552

merged 7 commits into from
Jul 6, 2016

Conversation

gavofyork
Copy link
Contributor

  • Client handles the enode message to avoid repeats.
  • Display journal DB strategy on startup.

@gavofyork gavofyork added the A0-pleasereview 🤓 Pull request needs code review. label Jul 6, 2016
}
}

impl<'a> Applyable for &'a String {
Copy link
Contributor

@rphmeier rphmeier Jul 6, 2016

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

Copy link
Contributor Author

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.

Copy link
Contributor

@rphmeier rphmeier Jul 6, 2016

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),
        }
    }
}

@rphmeier rphmeier added A8-looksgood 🦄 Pull request is reviewed well. and removed A0-pleasereview 🤓 Pull request needs code review. labels Jul 6, 2016
@gavofyork gavofyork merged commit cd7b046 into master Jul 6, 2016
@gavofyork gavofyork deleted the showdb branch July 6, 2016 16:28
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
A8-looksgood 🦄 Pull request is reviewed well.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants