yomorun / hashids-java

Hashids algorithm v1.0.0 implementation in Java
http://hashids.org
MIT License
1.02k stars 156 forks source link

reimplemented unhash using Horner's method #34

Closed jkramarz closed 7 years ago

jkramarz commented 7 years ago

This change is Reviewable

0x3333 commented 7 years ago

Review status: 0 of 1 files reviewed at latest revision, 2 unresolved discussions.


src/main/java/org/hashids/Hashids.java, line 386 at r1 (raw file):

    long number = 0;

    for (char item: input.toCharArray()) {

Could you implement without calling toCharArray()? Using charAt is much more efficient. Despite that, code is good, nice catch.


src/main/java/org/hashids/Hashids.java, line 387 at r1 (raw file):


    for (char item: input.toCharArray()) {
      long position = alphabet.indexOf(item);

Also, you could use the same pos variable instead of declaring inside the loop. This would make minimal modifications to code.


Comments from Reviewable

0x3333 commented 7 years ago

Hi @jkramarz any news on the modifications? Would be a nice addition to the project.

Thanks!

0x3333 commented 7 years ago

I'll close as we changed directly in master. Thanks @jkramarz.