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

performance improvements #53

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
14 changes: 13 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,18 @@
<version>4.12</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.openjdk.jmh</groupId>
<artifactId>jmh-core</artifactId>
<version>1.9</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.openjdk.jmh</groupId>
<artifactId>jmh-generator-annprocess</artifactId>
<version>1.9</version>
<scope>test</scope>
</dependency>
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why did you add this dependency?

Copy link
Author

Choose a reason for hiding this comment

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

My mistake. I have run a benchmark to check the performance. Thanks for seeing it! :)

</dependencies>

<contributors>
Expand All @@ -208,7 +220,7 @@
<url>https://github.com/TheConstructor</url>
</contributor>
<contributor>
<name>Mihai CAZACU</name>
<name>Mihai Cazacu</name>
<url>https://github.com/cazacugmihai</url>
</contributor>
</contributors>
Expand Down
6 changes: 4 additions & 2 deletions src/main/java/org/hashids/Hashids.java
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,10 @@ private void validateAlphabet(char[] alphabet) {
throw new IllegalArgumentException("The alphabet cannot contain spaces.");
}

if ((i + 1 < alphabet.length) && (alphabet[i] == alphabet[i + 1])) {
throw new IllegalArgumentException("The alphabet cannot contain duplicates.");
for (int j = i + 1; j < alphabet.length; j++) {
if (alphabet[i] == alphabet[j]) {
throw new IllegalArgumentException("The alphabet cannot contain duplicates.");
}
}
}
}
Expand Down