I hereby claim:
- I am martinmroz on github.
- I am martinmroz (https://keybase.io/martinmroz) on keybase.
- I have a public key ASAzlqHwmUQVK6z6SrEAFQhkWMoUThrk1qvLQbyPRpjdWQo
To claim this, I am signing this object:
I hereby claim:
To claim this, I am signing this object:
public protocol SimpleViewControllerDelegate: class { | |
func simpleViewControllerAction(_ viewController: SimpleViewController) | |
} | |
public final class SimpleViewController { | |
// MARK: - Public Properties | |
public weak var delegate: SimpleViewControllerDelegate? = nil |
public final class RootFlow { | |
// MARK: - Private Properties | |
private let navigationController: UINavigationController | |
private var presented: Bool = false | |
// MARK: - Private Properties - View Controllers | |
private lazy var simpleViewController = SimpleViewController(delegate: self) |
fn main() { | |
let target_path = std::env::args().nth(1).expect("No file path specified"); | |
// Count the bytes, words and lines in the specified file. | |
let whole_file_string = std::fs::read_to_string(&target_path).expect("Unable to read file"); | |
let bytes = whole_file_string.len(); | |
let words = whole_file_string.split_whitespace().count(); | |
let lines = whole_file_string.lines().count(); |
file | wc time | wc mem | wc_rs time | wc_rs mem | |
---|---|---|---|---|---|
empty.txt | 0.00s | 671kB | 0.00s | 753kB | |
big.txt | 0.02s | 1.72MB | 0.02s | 7.27MB | |
huge.txt | 0.32s | 1.72MB | 0.45s | 99.73MB |
file | wc time | wc mem | wc_rs time | wc_rs mem | |
---|---|---|---|---|---|
empty.txt | 0.00s | 671kB | 0.00s | 761kB | |
big.txt | 0.02s | 1.72MB | 0.02s | 1.29MB | |
huge.txt | 0.32s | 1.72MB | 0.35s | 1.29MB |
#[derive(Copy, Clone, Eq, PartialEq, Debug, Hash)] | |
struct Flux { | |
/// The type of the left-most character in the chunk. | |
pub leftmost_char_type: CharType, | |
/// The number of words in the chunk. | |
pub words: usize, | |
/// The number of lines in the chunk. | |
pub lines: usize, | |
/// The type of the right-most character in the chunk. | |
pub rightmost_char_type: CharType, |
let mut last_char_type = CharType::IsSpace; | |
'buffer_loop: loop { | |
let buffer = input.fill_buf()?; | |
let length = buffer.len(); | |
if length == 0 { | |
break 'buffer_loop; | |
} | |
// Update the byte counter from the buffer. |
impl From<u8> for Flux { | |
fn from(other: u8) -> Self { | |
if other.is_ascii_whitespace() { | |
// A line-feed is considered an ASCII whitespace character by `is_ascii_whitespace`. | |
let lines = if other == ('\n' as u8) { 1 } else { 0 }; | |
Flux::new(CharType::IsSpace, 0, lines, CharType::IsSpace) | |
} else { | |
Flux::new(CharType::NotSpace, 1, 0, CharType::NotSpace) | |
} | |
} |
fn span(self, rhs: Flux) -> Self { | |
let words = { | |
// If the span is formed along a non-space to non-space boundary the word count is one less than the sum. | |
if let (CharType::NotSpace, CharType::NotSpace) = (self.rightmost_char_type, rhs.leftmost_char_type) { | |
self.words + rhs.words - 1 | |
} else { | |
self.words + rhs.words | |
} | |
}; | |
Flux::new(self.leftmost_char_type, words, self.lines + rhs.lines, rhs.rightmost_char_type) |