/// first step of the build: we explore the directories and gather lines.
/// If there's no search pattern we stop when we have enough lines to fill the screen.
/// If there's a pattern, we try to gather more lines that will be sorted afterwards.
first step of the build: we explore the directories and gather lines.
If there's no search pattern we stop when we have enough lines to fill the screen.
If there's a pattern, we try to gather more lines that will be sorted afterwards.
first step of the build : we explore the directories and gather lines . If there ' s no search pattern we stop when we have enough lines to fill the screen . If there ' s a pattern we try to gather more lines that will be sorted afterwards .
fn gather_lines(&mut self, task_lifetime: &TaskLifetime) -> Option<Vec<BId>> {
        let start = Instant::now();
        let mut out_blines: Vec<BId> = Vec::new(); // the blines we want to display
        let not_long = Duration::from_millis(600);
        let optimal_size = self
            .options
            .pattern
            .optimal_result_number(self.targeted_size);
        out_blines.push(self.root_id);
        let mut nb_lines_ok = 1; // in out_blines
        let mut open_dirs: VecDeque<BId> = VecDeque::new();
        let mut next_level_dirs: Vec<BId> = Vec::new();
        self.load_children(self.root_id);
        open_dirs.push_back(self.root_id);
        loop {
            if (nb_lines_ok > optimal_size)
                || (nb_lines_ok >= self.targeted_size && start.elapsed() > not_long)
            {
                break;
            }
            if let Some(open_dir_id) = open_dirs.pop_front() {
                if let Some(child_id) = self.next_child(open_dir_id) {
                    open_dirs.push_back(open_dir_id);
                    let child = &self.blines[child_id];
                    if child.has_match {
                        nb_lines_ok += 1;
                    }
                    if child.file_type.is_dir() {
                        next_level_dirs.push(child_id);
                    }
                    out_blines.push(child_id);
                }
            } else {
                // this depth is finished, we must go deeper
                if self.options.show_sizes {
                    // both for technical reasons (bad sort) and ergonomics
                    //  ones (it proved to be hard to read), we don't want
                    //  a deep tree when looking at sizes.
                    break;
                }
                if next_level_dirs.is_empty() {
                    // except there's nothing deeper
                    break;
                }
                for next_level_dir_id in &next_level_dirs {
                    if task_lifetime.is_expired() {
                        info!("task expired (core build - inner loop)");
                        return None;
                    }
                    let has_child_match = self.load_children(*next_level_dir_id);
                    if has_child_match {
                        // we must ensure the ancestors are made Ok
                        let mut id = *next_level_dir_id;
                        loop {
                            let mut bline = &mut self.blines[id];
                            if !bline.has_match {
                                bline.has_match = true;
                                nb_lines_ok += 1;
                            }
                            if let Some(pid) = bline.parent_id {
                                id = pid;
                            } else {
                                break;
                            }
                        }
                    }
                    open_dirs.push_back(*next_level_dir_id);
                }
                next_level_dirs.clear();
            }
        }
        if self.options.show_sizes || !self.options.trim_root {
            // if the root directory isn't totally read, we finished it even
            // it it goes past the bottom of the screen
            while let Some(child_id) = self.next_child(self.root_id) {
                out_blines.push(child_id);
            }
        }
        Some(out_blines)
    }
fn gather_lines ( & mut self , task_lifetime : & TaskLifetime ) -> Option < Vec < BId > > { let start = Instant :: now ( ) ; let mut out_blines : Vec < BId > = Vec :: new ( ) ; // the blines we want to display let not_long = Duration :: from_millis ( 600 ) ; let optimal_size = self . options . pattern . optimal_result_number ( self . targeted_size ) ; out_blines . push ( self . root_id ) ; let mut nb_lines_ok = 1 ; // in out_blines let mut open_dirs : VecDeque < BId > = VecDeque :: new ( ) ; let mut next_level_dirs : Vec < BId > = Vec :: new ( ) ; self . load_children ( self . root_id ) ; open_dirs . push_back ( self . root_id ) ; loop { if ( nb_lines_ok > optimal_size ) || ( nb_lines_ok >= self . targeted_size && start . elapsed ( ) > not_long ) { break ; } if let Some ( open_dir_id ) = open_dirs . pop_front ( ) { if let Some ( child_id ) = self . next_child ( open_dir_id ) { open_dirs . push_back ( open_dir_id ) ; let child = & self . blines [ child_id ] ; if child . has_match { nb_lines_ok += 1 ; } if child . file_type . is_dir ( ) { next_level_dirs . push ( child_id ) ; } out_blines . push ( child_id ) ; } } else { // this depth is finished, we must go deeper if self . options . show_sizes { // both for technical reasons (bad sort) and ergonomics //  ones (it proved to be hard to read), we don't want //  a deep tree when looking at sizes. break ; } if next_level_dirs . is_empty ( ) { // except there's nothing deeper break ; } for next_level_dir_id in & next_level_dirs { if task_lifetime . is_expired ( ) { info ! ( " " ) ; return None ; } let has_child_match = self . load_children ( * next_level_dir_id ) ; if has_child_match { // we must ensure the ancestors are made Ok let mut id = * next_level_dir_id ; loop { let mut bline = & mut self . blines [ id ] ; if ! bline . has_match { bline . has_match = true ; nb_lines_ok += 1 ; } if let Some ( pid ) = bline . parent_id { id = pid ; } else { break ; } } } open_dirs . push_back ( * next_level_dir_id ) ; } next_level_dirs . clear ( ) ; } } if self . options . show_sizes || ! self . options . trim_root { // if the root directory isn't totally read, we finished it even // it it goes past the bottom of the screen while let Some ( child_id ) = self . next_child ( self . root_id ) { out_blines . push ( child_id ) ; } } Some ( out_blines ) }
first step of the build: we explore the directories and gather lines.
first step of the build : we explore the directories and gather lines .
&mut self
task_lifetime
&TaskLifetime