Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix path search #46081

Merged
merged 2 commits into from
Nov 25, 2017
Merged

Fix path search #46081

merged 2 commits into from
Nov 25, 2017

Conversation

GuillaumeGomez
Copy link
Member

@GuillaumeGomez GuillaumeGomez force-pushed the fix-path-search branch 3 times, most recently from 7d0d016 to 8da48f2 Compare November 18, 2017 16:34
@shepmaster shepmaster added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Nov 18, 2017
@QuietMisdreavus
Copy link
Member

This changes the behavior when searching for paths, but it doesn't quite fix the issue?

Your PR

image

Current nightly

image

Current stable

image

@GuillaumeGomez
Copy link
Member Author

Oh damn. Didn't take into account cases where the path doesn't start by the given search... I'll update it.

@GuillaumeGomez
Copy link
Member Author

Ok fixed! The changed line is this one.

@GuillaumeGomez
Copy link
Member Author

After thinking about it once again (and a few tests), I found my solution not good enough so I strongly improved the checkPath function. Works way better now.

split.splice(j, 1);
for (var z = 0; z < split.length; ++z) {
if (split[z] === "") {
split.slice(z, 1);
Copy link
Contributor

Choose a reason for hiding this comment

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

Slice returns a new array, so this is a no-op. Did you want to .splice() instead? From the removed code side, it looks like the answer is yes.

More idiomatically, you can also push those that raen't the empty string.

Copy link
Member Author

Choose a reason for hiding this comment

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

> x = [1,2,3];
(3) [1, 2, 3]
> x.splice(0, 1)
[1]
> x
(2) [2, 3]

So no, it clearly removes an entry from the array.

Copy link
Member Author

Choose a reason for hiding this comment

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

Oh damn, you're absolutely right. Didn't see the missing 'p'!

@GuillaumeGomez
Copy link
Member Author

Fixed.

Copy link
Contributor

@Havvy Havvy left a comment

Choose a reason for hiding this comment

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

Just checking for basic JS stuff, and no other basic JS mistakes found.

return MAX_LEV_DISTANCE + 1;
}
for (var i = 0; i < path.length; ++i) {
if (i + startsWith.length > path.length) {
Copy link

Choose a reason for hiding this comment

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

You can use the condition used in the if statement as the for loop condition (when inverted), can't you?

Copy link
Member Author

Choose a reason for hiding this comment

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

Absolutely. I just have a personal preference to keep loop conditions as simple as possible. If someone else thinks it's a good idea, then I'll just update it.

}
lev_total += lev;
}
if (aborted === false) {
Copy link

Choose a reason for hiding this comment

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

Isn't it more common to check it like this: !aborted

Copy link
Member Author

Choose a reason for hiding this comment

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

It's slower. '!' tests (from memory): length !== 0, 0, null, undefined. So clearly, it's way better in js to make the comparison like this.

Copy link

Choose a reason for hiding this comment

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

Didn't know that. Thanks for explaining it.

Copy link
Contributor

Choose a reason for hiding this comment

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

Except you can generally rely on the JIT to figure out that aborted can only contain a boolean.

Copy link
Member Author

Choose a reason for hiding this comment

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

I did too much rust, I love being explicit. 😛

@QuietMisdreavus
Copy link
Member

@bors r+

@bors
Copy link
Contributor

bors commented Nov 25, 2017

📌 Commit c00eaa9 has been approved by QuietMisdreavus

@bors
Copy link
Contributor

bors commented Nov 25, 2017

⌛ Testing commit c00eaa9 with merge ca8ef26...

bors added a commit that referenced this pull request Nov 25, 2017
@bors
Copy link
Contributor

bors commented Nov 25, 2017

☀️ Test successful - status-appveyor, status-travis
Approved by: QuietMisdreavus
Pushing ca8ef26 to master...

@bors bors merged commit c00eaa9 into rust-lang:master Nov 25, 2017
@bors bors mentioned this pull request Nov 25, 2017
@GuillaumeGomez GuillaumeGomez deleted the fix-path-search branch November 25, 2017 15:28
@kennytm kennytm added the beta-nominated Nominated for backporting to the compiler in the beta channel. label Nov 27, 2017
bors added a commit that referenced this pull request Dec 23, 2017
[beta] Doc search backports

This is a backport of #46081, #46175, #46433, and #46672. They all merged cleanly but I haven't tried a build; let's see what Travis says.

These PRs fix pretty annoying issues with doc search and so I think it's important they don't slip to stable, but these PRs have *NOT* been `beta-accepted` yet.

cc @steveklabnik @GuillaumeGomez can you tag the docs team to talk about beta-acceptance?
@alexcrichton
Copy link
Member

Looks like we forgot to backport this to 1.23.0 (sorry about that!) so removing beta tags

@alexcrichton alexcrichton removed the beta-nominated Nominated for backporting to the compiler in the beta channel. label Jan 10, 2018
@alexcrichton
Copy link
Member

Er sorry, looks like this was backported in #46886

@alexcrichton alexcrichton added the beta-accepted Accepted for backporting to the compiler in the beta channel. label Jan 10, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
beta-accepted Accepted for backporting to the compiler in the beta channel. S-waiting-on-review Status: Awaiting review from the assignee but also interested parties.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants