Skip to content

Avoid some allocations#8

Merged
fitzgen merged 3 commits intomasterfrom
unknown repository
Nov 4, 2021
Merged

Avoid some allocations#8
fitzgen merged 3 commits intomasterfrom
unknown repository

Conversation

@ghost
Copy link

@ghost ghost commented Jun 22, 2021

Hello, I've taken a closer look at the Windows implementation of is_executable and I think this can be optimized. First, I believe the to_string_lossy can simply be removed from both extension and pathext and shouldn't affect the comparison but I could be wrong on that one so please test this if you are able to.
As for the .map(|ext| ext[1..].to_string()), I was able to remove the to_string by simply merging the cut-off into the any. The collect is unnecessary and the any iteration can simply be done immediately instead of collecting into a Vec first.

@ghost
Copy link
Author

ghost commented Jul 6, 2021

I'm not entirely sure why it fails but I'm going to close this for now.

@ghost ghost closed this Jul 6, 2021
Copy link
Contributor

@alpha-tango-kilo alpha-tango-kilo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hiya, not a maintainer or the owner but I noticed you submitted this PR optimising code I contributed. It's a really quick fix for you to apply then hopefully we can get this merged!

When I originally wrote the extension-checking part of the program I was still pretty novice-level at Rust, so I appreciate you coming back and improving on my work

src/lib.rs Outdated

// Originally taken from:
// https://github.com/nushell/nushell/blob/93e8f6c05e1e1187d5b674d6b633deb839c84899/crates/nu-cli/src/completion/command.rs#L64-L74
let pathext = pathext
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the only part that's not quite right. You removed the original return statement I had and haven't provided it again, meaning the program always falls back to the old logic (lines 132 onwards of your branch)

diff --git a/src/lib.rs b/src/lib.rs
index 8b1c664..dfc71e5 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -117,7 +117,7 @@ mod windows {
                     
                     // Originally taken from:
                     // https://github.com/nushell/nushell/blob/93e8f6c05e1e1187d5b674d6b633deb839c84899/crates/nu-cli/src/completion/command.rs#L64-L74
-                    let pathext = pathext
+                    return pathext
                         .to_string_lossy()
                         .split(';')
                         // Filter out empty tokens and ';' at the end

This'll make tests pass and reduce allocations as you intended

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, hello! Alright, let's try that.

@ghost ghost reopened this Nov 2, 2021
@alpha-tango-kilo
Copy link
Contributor

Let's get this merged! @fitzgen

If you wanted help maintaining the project, I'd be happy to offer my services :)

@fitzgen fitzgen merged commit 4923b31 into fitzgen:master Nov 4, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants