-
Notifications
You must be signed in to change notification settings - Fork 12
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
Option to omit toString
generation
#50
Comments
An integer is its own hashCode, and the function is documented to simply return the input on the JVM. For JS and native the behavior is the same: https://github.com/JetBrains/kotlin/blob/1.9.0/kotlin-native/runtime/src/main/kotlin/kotlin/Primitives.kt#L1353. Saves at least 3 bytes per property within the function bytecode, not counting any effects on things like the constant pool (for JVM). Before: public int hashCode(); Code: 0: aload_0 1: getfield #23 // Field int:I 4: invokestatic #50 // Method java/lang/Integer.hashCode:(I)I 7: istore_1 8: iload_1 9: bipush 31 11: imul ⋮ 46: ireturn After: public int hashCode(); Code: 0: aload_0 1: getfield #23 // Field int:I 4: istore_1 5: iload_1 6: bipush 31 8: imul ⋮ 43: ireturn
There are a few API design options that come to mind. These all interact with #67's design in some way, so probably both designs need to be fleshed out at the same time.
@Poko(
equals = INCLUDED|EXCLUDED|MEMOIZED,
hashCode = INCLUDED|EXCLUDED|MEMOIZED,
toString = INCLUDED|EXCLUDED|MEMOIZED,
)
|
Generated
toString
implementations add to the string pool, and can't be removed by optimizers like R8 due to the general widely-used nature oftoString
. For this reason it is desirable in some contexts to skiptoString
—only generateequals
andhashCode
—on internal value types. It would be nice if Poko had a way to do this for some, but not all, classes in a module/project.In the meantime, it's possible to achieve the desired behavior manually:
The text was updated successfully, but these errors were encountered: