We do not need to track shift amount, as we can can just shift
the entire previous result, leading to more invariants in the loop.
JIRA: MDSAL-509
Change-Id: I13a108be27cac2fe4498952f3f05437927c999c0
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
(cherry picked from commit
4b26656c945b9af5e67d28d10b014b0ed37cc510)
static int addressBits(final String str, final int limit) {
int prev = 0;
int current = 0;
- for (int i = 0, shift = 24; i < limit; ++i) {
+ for (int i = 0; i < limit; ++i) {
final char c = str.charAt(i);
if (c == '.') {
- prev |= current << shift;
- shift -= 8;
+ prev = prev << 8 | current;
current = 0;
} else {
current = 10 * current + c - '0';
}
}
- return prev | current;
+ return prev << 8 | current;
}
static byte @NonNull[] addressBytes(final String str, final int limit) {