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

[Refactor] Use "case" instead of multi "if" #1332

Merged
merged 1 commit into from
Nov 30, 2016

Conversation

PeterDaveHello
Copy link
Collaborator

This can also help us use the more flexible pattern matching in "case" in future.

Copy link
Member

@ljharb ljharb left a comment

Choose a reason for hiding this comment

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

Isn't case slower than multiple ifs?

"_sunos")
NVM_CPU_CORES="$(psrinfo | wc -l)";;
"_aix")
NVM_CPU_CORES="$(lsconf | command grep 'Number Of Processors:'| command awk '{print $4}')";;
Copy link
Member

Choose a reason for hiding this comment

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

If the contents of the case are not on the same line as the ), then the closing ;; should be on a line by itself.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Updated, thanks.

NVM_CPU_CORES="$(psrinfo | wc -l)"
;;
"_aix")
NVM_CPU_CORES="$(lsconf | command grep 'Number Of Processors:'| command awk '{print $4}')"
Copy link
Member

Choose a reason for hiding this comment

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

heads up, this is going to conflict with #1319 which is being merged shortly.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I think we both can update this part immediately, right?

Copy link
Member

Choose a reason for hiding this comment

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

It's merged; feel free to rebase

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done.

@ljharb
Copy link
Member

ljharb commented Nov 28, 2016

@PeterDaveHello what about my question above?

@PeterDaveHello
Copy link
Collaborator Author

@ljharb oops, is there any reference about the difference? I wonder if it's that significant that we should worry about it, use so many if/else may not be a good implement, and also, I want to add one more OS type in nvm called alpine_linux, to disable install from binary for Alpine linux by default as FreeBSD, but at the same time, many other parts should share the same thing just as linux, so case can help us do that by more flexible matching.

@ljharb ljharb changed the title [Refactor] Use "case" hinstead of multi "if" [Refactor] Use "case" instead of multi "if" Nov 28, 2016
@ljharb
Copy link
Member

ljharb commented Nov 28, 2016

Why would we want to disable the binary install for alpine linux? node is considering adding support for alpine linux, so I think the check should always be done.

@PeterDaveHello
Copy link
Collaborator Author

Just like: Not all node/io.js versions have a Solaris binary, what about the old versions? Will they build all the old versions for Alpine Linux?

@ljharb
Copy link
Member

ljharb commented Nov 29, 2016

Not all of them, but a good percentage, yes - at least, that's what I'm advocating for.

@PeterDaveHello
Copy link
Collaborator Author

Then that's the part once they provided the binary for Alpine, before that, the behavior should be like FreeBSD, but no matter which one, I think we don't need to bundle with this PR, not the same issue.

Copy link
Member

@ljharb ljharb left a comment

Choose a reason for hiding this comment

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

This isn't performance-critical code, so I'm OK with using the case here.

@ljharb ljharb merged commit 84575cf into nvm-sh:master Nov 30, 2016
@PeterDaveHello PeterDaveHello deleted the refactor branch November 30, 2016 11:09
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