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

some additional performance improvements #39

Merged
merged 7 commits into from
Sep 13, 2022
9 changes: 5 additions & 4 deletions src/main/software/amazon/event/ruler/Range.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
* implementation, the number of digits in the top and bottom of the range is the same.
*/
public class Range extends Patterns {

/**
* Bottom and top of the range. openBottom true means we're looking for > bottom, false means >=
* Similarly, openTop true means we're looking for < top, false means <= top.
Expand All @@ -21,6 +20,8 @@ public class Range extends Patterns {

final boolean isCIDR;

private static final int HEX_DIGIT_A_DECIMAL_VALUE = 10;

private Range(final double bottom, final boolean openBottom, final double top, final boolean openTop) {
super(MatchType.NUMERIC_RANGE);
if (bottom >= top) {
Expand Down Expand Up @@ -108,11 +109,11 @@ static byte[] digitSequence(byte first, byte last, boolean includeFirst, boolean

private static int getHexByteIndex(byte value) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@jonessha what do you think? I feel like using the chars helps with the clarity , and then only one obscure constant is needed

Copy link
Contributor

Choose a reason for hiding this comment

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

This looks good! Thank you!

// ['0'-'9'] maps to [0-9] indexes
if (value >= 48 && value <= 57) {
return value - 48;
if (value >= '0' && value <= '9') {
return value - '0';
}
// ['A'-'F'] maps to [10-15] indexes
return (value - 65) + 10;
return (value - 'A') + HEX_DIGIT_A_DECIMAL_VALUE;
}

@Override
Expand Down