Repository: starship/starship
File: src/context.rs (Rust)

Code before:
                || start.elapsed() < timeout
            })
            .filter_map(|(_, entry)| entry.ok())
            .for_each(|entry| {
                let path = PathBuf::from(entry.path().strip_prefix(base).unwrap());
                if entry.path().is_dir() {
                    folders.insert(path);
                } else {
                    if !path.to_string_lossy().starts_with('.') {
                        // Extract the file extensions (yes, that's plural) from a filename.
                        // Why plural? Consider the case of foo.tar.gz. It's a compressed
                        // tarball (tar.gz), and it's a gzipped file (gz). We should be able
                        // to match both.

                        // find the minimal extension on a file. ie, the gz in foo.tar.gz
                        path.extension()
                            .map(|ext| extensions.insert(ext.to_string_lossy().to_string()));

                        // find the full extension on a file. ie, the tar.gz in foo.tar.gz
                        path.file_name().map(|file_name| {
                            file_name
                                .to_string_lossy()
                                .to_string()
                                .split_once('.')
                                .map(|(_, after)| extensions.insert(after.to_string()))
                        });
                    }
                    if let Some(file_name) = path.file_name() {
                        file_names.insert(file_name.to_string_lossy().to_string());
                    }
                    files.insert(path);
                }
            });

        log::trace!(
            "Building HashSets of directory files, folders and extensions took {:?}",
            start.elapsed()
        );

        Ok(Self {
            files,
            file_names,
            folders,
            extensions,
        })
    }

    pub fn files(&self) -> impl Iterator<Item = &PathBuf> {
        self.files.iter()
    }


Review comment (performance):
We will need to evaluate if this will have a performance impact when there are a large number of files.

Code after:
                || start.elapsed() < timeout
            })
            .filter_map(|(_, entry)| entry.ok())
            .for_each(|entry| {
                let path = PathBuf::from(entry.path().strip_prefix(base).unwrap());
                if entry.path().is_dir() {
                    folders.insert(path);
                } else {
                    if !path.to_string_lossy().starts_with('.') {
                        // Extract the file extensions (yes, that's plural) from a filename.
                        // Why plural? Consider the case of foo.tar.gz. It's a compressed
                        // tarball (tar.gz), and it's a gzipped file (gz). We should be able
                        // to match both.

                        // find the minimal extension on a file. ie, the gz in foo.tar.gz
                        // NB the .to_string_lossy().to_string() here looks weird but is
                        // required to convert it from a Cow.
                        path.extension()
                            .map(|ext| extensions.insert(ext.to_string_lossy().to_string()));

                        // find the full extension on a file. ie, the tar.gz in foo.tar.gz
                        path.file_name().map(|file_name| {
                            file_name
                                .to_string_lossy()
                                .split_once('.')
                                .map(|(_, after)| extensions.insert(after.to_string()))
                        });
                    }
                    if let Some(file_name) = path.file_name() {
                        // this .to_string_lossy().to_string() is also required
                        file_names.insert(file_name.to_string_lossy().to_string());
                    }
                    files.insert(path);
                }
            });

        log::trace!(
            "Building HashSets of directory files, folders and extensions took {:?}",
            start.elapsed()
        );

        Ok(Self {
            files,
            file_names,
            folders,
            extensions,
        })
    }

    pub fn files(&self) -> impl Iterator<Item = &PathBuf> {
        self.files.iter()