From 1afff777a6f7ca39c6c2ee0f5ecb57ebfab7cbd4 Mon Sep 17 00:00:00 2001 From: Darren Schroeder <343840+fdncred@users.noreply.github.com> Date: Wed, 25 Sep 2024 08:15:18 -0500 Subject: [PATCH] update folder_depth algorithm for glob command (#13915) # Description This PR updates the `folder_depth` algorithm in order to make `glob` a bit faster. The algorithm works like this. Since `folder_depth` is always used we need to set it to a value. If the glob pattern contains `**` then make `folder_depth` `usize::MAX`. If `--depth` is not provided, make it 1, otherwise use the provided value. closes #13914 # User-Facing Changes # Tests + Formatting # After Submitting --- crates/nu-command/src/filesystem/glob.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/crates/nu-command/src/filesystem/glob.rs b/crates/nu-command/src/filesystem/glob.rs index d6243bbc32..219853f6cb 100644 --- a/crates/nu-command/src/filesystem/glob.rs +++ b/crates/nu-command/src/filesystem/glob.rs @@ -171,8 +171,12 @@ impl Command for Glob { let folder_depth = if let Some(depth) = depth { depth - } else { + } else if glob_pattern.contains("**") { usize::MAX + } else if glob_pattern.contains(std::path::MAIN_SEPARATOR) { + glob_pattern.split(std::path::MAIN_SEPARATOR).count() + 1 + } else { + 1 }; let (prefix, glob) = match WaxGlob::new(&glob_pattern) {