Repository: nushell/nushell
File: crates/nu-cli/src/completions/completion_common.rs (Rust)

Code before:
            let mut built = built.clone();
            built.parts.push(entry_name.clone());
            // Symlinks to directories shouldn't have a trailing slash (#13275)
            built.isdir = entry_isdir && !entry.path().is_symlink();

            if !want_directory || entry_isdir {
                matcher.add(entry_name.clone(), (entry_name, built));
            }
        }
    }

    let mut completions = vec![];
    for (entry_name, built) in matcher.results() {
        match partial.split_first() {
            Some((base, rest)) => {
                // We use `isdir` to confirm that the current component has
                // at least one next component or a slash.
                // Serves as confirmation to ignore longer completions for
                // components in between.
                if !rest.is_empty() || isdir {
                    // Don't show longer completions if we have an exact match (#13204, #14794)
                    let exact_match = enable_exact_match
                        && (if options.case_sensitive {
                            entry_name.eq(base)
                        } else {
                            entry_name.to_folded_case().eq(&base.to_folded_case())
                        });
                    completions.extend(complete_rec(
                        rest,
                        &[built],
                        options,
                        want_directory,
                        isdir,
                        exact_match,
                    ));
                    if exact_match {
                        break;
                    }
                } else {
                    completions.push(built);
                }
            }
            None => {
                completions.push(built);
            }
        }
    }
    completions
}

#[derive(Debug)]

Review comment (suggestion):
I know this line isn't from this PR, but you can avoid the two `String` allocations here:

```suggestion
                            entry_name.eq_ignore_case(&base)
```

Code after:
            let mut built = built.clone();
            built.parts.push(entry_name.clone());
            // Symlinks to directories shouldn't have a trailing slash (#13275)
            built.isdir = entry_isdir && !entry.path().is_symlink();

            if !want_directory || entry_isdir {
                matcher.add(entry_name.clone(), (entry_name, built));
            }
        }
    }

    let mut completions = vec![];
    for (entry_name, built) in matcher.results() {
        match partial.split_first() {
            Some((base, rest)) => {
                // We use `isdir` to confirm that the current component has
                // at least one next component or a slash.
                // Serves as confirmation to ignore longer completions for
                // components in between.
                if !rest.is_empty() || isdir {
                    // Don't show longer completions if we have an exact match (#13204, #14794)
                    let exact_match = enable_exact_match
                        && (if options.case_sensitive {
                            entry_name.eq(base)
                        } else {
                            entry_name.eq_ignore_case(base)
                        });
                    completions.extend(complete_rec(
                        rest,
                        &[built],
                        options,
                        want_directory,
                        isdir,
                        exact_match,
                    ));
                    if exact_match {
                        break;
                    }
                } else {
                    completions.push(built);
                }
            }
            None => {
                completions.push(built);
            }
        }
    }
    completions
}

#[derive(Debug)]