Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 3 additions & 14 deletions flink-core/src/main/java/org/apache/flink/util/MathUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,8 @@ public static int log2floor(int value) throws ArithmeticException {
if (value == 0) {
throw new ArithmeticException("Logarithm of zero is undefined.");
}

int log = 0;
while ((value = value >>> 1) != 0) {
log++;
}

return log;

return 31 - Integer.numberOfLeadingZeros(value);
}

/**
Expand All @@ -62,13 +57,7 @@ public static int log2strict(int value) throws ArithmeticException, IllegalArgum
if ((value & (value - 1)) != 0) {
throw new IllegalArgumentException("The given value " + value + " is not a power of two.");
}

int log = 0;
while ((value = value >>> 1) != 0) {
log++;
}

return log;
return 31 - Integer.numberOfLeadingZeros(value);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

import org.apache.flink.types.IntValue;
import org.apache.flink.types.LongValue;
import org.apache.flink.util.MathUtils;

/**
* Translate {@link LongValue} to {@link IntValue}.
Expand All @@ -32,17 +33,11 @@ public class LongValueToIntValue
@Override
public IntValue translate(LongValue value, IntValue reuse)
throws Exception {
long val = value.getValue();

if (val > Integer.MAX_VALUE) {
throw new RuntimeException("LongValue input overflows IntValue output");
}

if (reuse == null) {
reuse = new IntValue();
}

reuse.setValue((int) val);
reuse.setValue(MathUtils.checkedDownCast(value.getValue()));
return reuse;
}
}