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

More efficient long conversion for negative ints in VarIntCodec #436

Merged

Conversation

aartigao
Copy link
Contributor

Two bitwise operations can be squashed into a single one.

Paranoid extra mode on, here's the bytecode before/after:

Before

public long scodec$codecs$VarIntCodec$$$toPositiveLong(int);
  Code:
     0: iload_1
     1: iconst_0
     2: if_icmplt     8
     5: iload_1
     6: i2l
     7: lreturn
     8: iload_1
     9: ldc           #21                 // int 2147483647
    11: iand
    12: i2l
    13: getstatic     #23                 // Field NegativeIntSignBit:J
    16: lor
    17: lreturn

After

public long scodec$codecs$VarIntCodec$$$toPositiveLong(int);
  Code:
     0: iload_1
     1: iconst_0
     2: if_icmplt     8
     5: iload_1
     6: i2l
     7: lreturn
     8: iload_1
     9: i2l
    10: ldc2_w        #29                 // long 4294967295l
    13: land
    14: lreturn

Two bitwise operations can be squashed into a single one.
@mpilquist mpilquist merged commit a512f4c into scodec:main Dec 13, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants