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

Comments

Projects
None yet
2 participants
@lukaseder
Copy link
Member

commented Jun 7, 2019

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

This comment has been minimized.

Copy link
Contributor

commented Jun 7, 2019

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

This comment has been minimized.

Copy link
Member Author

commented Jun 7, 2019

Agreed

@knutwannheden

This comment has been minimized.

Copy link
Contributor

commented Jun 7, 2019

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

knutwannheden added a commit that referenced this issue Jun 7, 2019

[#18] Improved hashCode() and toString() implementation
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

[#18] Improved hashCode() and toString() implementation
Changed code for multi-release compatibility.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.