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

Improved hashCode() and toString() implementation #18

Closed
lukaseder opened this issue Jun 7, 2019 · 3 comments
Closed

Improved hashCode() and toString() implementation #18

lukaseder opened this issue Jun 7, 2019 · 3 comments

Comments

@lukaseder
Copy link
Member

The current implementation on e.g. UByte.toString() is:

    @Override
    public String toString() {
        return Short.valueOf(value).toString();
    }

This produces an unnecessary allocation of a java.lang.Short, when instead, we could write

    @Override
    public String toString() {
        return Short.toString(value);
    }

Other types are also affected.

Credits to @knutwannheden for discovering this.

@knutwannheden
Copy link
Contributor

In the scope of this issue I will also fix the hashCode() methods which can be optimized in the exact same way.

@lukaseder lukaseder changed the title Improved toString() implementation Improved hashCode() and toString() implementation Jun 7, 2019
@lukaseder
Copy link
Member Author

Agreed

@knutwannheden
Copy link
Contributor

Unfortunately only since Java 1.8, so not in jOOU-java-6.

knutwannheden added a commit that referenced this issue Jun 7, 2019
Instead of `Short.valueOf(value).toString()` we can implement
`UByte#toString()` as `Short.toString(value)`. Also `UByte#hashCode()`
can be changed from `Short.valueOf(value).hashCode()` to
`Short.hashCode(value)` as of Java 1.8.

Same changes for `UInteger` and `UShort` and also to `ULong` for the
`hashCode()` implementation.
knutwannheden added a commit that referenced this issue Jun 7, 2019
Changed code for multi-release compatibility.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants