Skip to content

Commit

Permalink
Use Iterator::sum() instead of fold()
Browse files Browse the repository at this point in the history
This simplifies the code a tiny bit.
  • Loading branch information
linkmauve authored Feb 17, 2023
1 parent f444a31 commit 78cfe57
Showing 1 changed file with 2 additions and 4 deletions.
6 changes: 2 additions & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,6 @@ extern crate test;
use tables::charwidth as cw;
pub use tables::UNICODE_VERSION;

use core::ops::Add;

mod tables;

#[cfg(test)]
Expand Down Expand Up @@ -121,11 +119,11 @@ pub trait UnicodeWidthStr {
impl UnicodeWidthStr for str {
#[inline]
fn width(&self) -> usize {
self.chars().map(|c| cw::width(c, false).unwrap_or(0)).fold(0, Add::add)
self.chars().map(|c| cw::width(c, false).unwrap_or(0)).sum()
}

#[inline]
fn width_cjk(&self) -> usize {
self.chars().map(|c| cw::width(c, true).unwrap_or(0)).fold(0, Add::add)
self.chars().map(|c| cw::width(c, true).unwrap_or(0)).sum()
}
}

0 comments on commit 78cfe57

Please sign in to comment.