Sebastian Thielgeneralize chunk iterator905e85e6 years agoHistory
79 lines · 1.9 KB · Rust
RawDownload
use crate::pack;use git_features::progress::Progress;use std::time::{Instant, SystemTime}; pub(crate) fn index_entries_sorted_by_offset_ascending(    idx: &pack::index::File,    mut progress: impl Progress,) -> Vec<pack::index::Entry> {    progress.init(Some(idx.num_objects), Some("entries"));    let then = SystemTime::now();     let mut v = Vec::with_capacity(idx.num_objects as usize);    for entry in idx.iter() {        v.push(entry);        progress.inc();    }    v.sort_by_key(|e| e.pack_offset);     let elapsed = then.elapsed().expect("system time").as_secs_f32();    progress.info(format!(        "in {:.02}s ({} entries/s)",        elapsed,        idx.num_objects as f32 / elapsed    ));    v} pub(crate) struct TimeThroughput {    then: Instant,    byte_size: usize,} impl TimeThroughput {    pub fn new(byte_size: usize) -> TimeThroughput {        TimeThroughput {            then: Instant::now(),            byte_size,        }    }} impl Into<String> for TimeThroughput {    fn into(self) -> String {        let time_taken = std::time::Instant::now().duration_since(self.then).as_secs_f32();        format!(            "finished in {:.2}s at {}/s",            time_taken,            bytesize::ByteSize((self.byte_size as f32 / time_taken) as u64)        )    }} pub(crate) struct Chunks<I> {    pub size: usize,    pub iter: I,}impl<I, Item> Iterator for Chunks<I>where    I: Iterator<Item = Item>,{    type Item = Vec<Item>;     fn next(&mut self) -> Option<Self::Item> {        let mut res = Vec::with_capacity(self.size);        let mut items_left = self.size;        while let Some(item) = self.iter.next() {            res.push(item);            items_left -= 1;            if items_left == 0 {                break;            }        }        if res.is_empty() {            None        } else {            Some(res)        }    }}

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t