Skip to content

Efficiency #732

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

Merged
merged 2 commits into from
May 10, 2019
Merged

Efficiency #732

merged 2 commits into from
May 10, 2019

Conversation

markettes
Copy link
Contributor

Just two small things that in case the number was very big could be helpful.

Just two small things that in case the number was very big could be helpful.
@markettes
Copy link
Contributor Author

I have been testing both ways to do it measuring time. Both are very fast and truly this pull request doesn't fix anything very important, but when the computer is working in other things and interrupts the thread, in your case you have a small delay. On the other hand, my solution makes it an atomic operation.
Thanks.

@@ -24,8 +24,8 @@
public static String encode(String message, int shift) {
String encoded = "";

while (shift >= 26) { // 26 = number of latin letters
shift -= 26;
if (shift >= 26) { // 26 = number of latin letters

Choose a reason for hiding this comment

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

Good catch! In fact, even this if is not necessary, since the modulo operation is no-op if shift < 26, i.e.

shift % 26 == shift if 0 <= shift < 26

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh! That's true! Less code then :)

@havanagrawal
Copy link

havanagrawal commented May 2, 2019

LGTM :)

@yanglbme yanglbme merged commit 8d1a81b into TheAlgorithms:master May 10, 2019
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.

3 participants