Skip to content

Commit

Permalink
bench with Options and usize, inline trait impls
Browse files Browse the repository at this point in the history
  • Loading branch information
mgeisler committed Sep 26, 2020
1 parent 5abeb29 commit a52bd44
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
4 changes: 4 additions & 0 deletions benches/linear.rs
Expand Up @@ -28,6 +28,10 @@ pub fn benchmark(c: &mut Criterion) {
b.iter(|| textwrap::fill(text, &options));
});

group.bench_with_input(BenchmarkId::new("fill_usize", length), &text, |b, text| {
b.iter(|| textwrap::fill(text, *length));
});

#[cfg(feature = "hyphenation")]
{
use hyphenation::{Language, Load, Standard};
Expand Down
10 changes: 10 additions & 0 deletions src/lib.rs
Expand Up @@ -162,36 +162,46 @@ impl<'indent> WrapOptions<'indent> for Options<'indent> {
}

impl<'indent> WrapOptions<'indent> for &Options<'indent> {
#[inline]
fn width(&self) -> usize {
self.width
}
#[inline]
fn initial_indent(&self) -> &'indent str {
self.initial_indent
}
#[inline]
fn subsequent_indent(&self) -> &'indent str {
self.subsequent_indent
}
#[inline]
fn break_words(&self) -> bool {
self.break_words
}
#[inline]
fn split<'w>(&self, word: &'w str) -> Vec<(&'w str, &'w str, &'w str)> {
self.splitter.split(word)
}
}

impl<'a> WrapOptions<'a> for usize {
#[inline]
fn width(&self) -> usize {
*self
}
#[inline]
fn initial_indent(&self) -> &'a str {
""
}
#[inline]
fn subsequent_indent(&self) -> &'a str {
""
}
#[inline]
fn break_words(&self) -> bool {
true
}
#[inline]
fn split<'w>(&self, word: &'w str) -> Vec<(&'w str, &'w str, &'w str)> {
let s = HyphenSplitter;
s.split(word)
Expand Down

0 comments on commit a52bd44

Please sign in to comment.