Skip to content

Commit

Permalink
[Java] Tidy up after merge of PR #118.
Browse files Browse the repository at this point in the history
  • Loading branch information
mjpt777 committed Dec 12, 2017
1 parent 4b31c7e commit 3a0169a
Show file tree
Hide file tree
Showing 6 changed files with 233 additions and 211 deletions.
3 changes: 2 additions & 1 deletion agrona/src/main/java/org/agrona/AsciiEncodingHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,20 @@
*/
public class AsciiEncodingHelper
{
public static final byte NEGATIVE = '-';
public static final byte ZERO = '0';
private static final int[] INT_ROUNDS =
{
9, 99, 999, 9999, 99999, 999999, 9999999, 99999999, 999999999, Integer.MAX_VALUE
};

private static final long[] LONG_ROUNDS =
{
9L, 99L, 999L, 9999L, 99999L, 999999L, 9999999L, 99999999L, 999999999L,
9_999999999L, 99_999999999L, 999_999999999L, 9999_999999999L,
99999_999999999L, 999999_999999999L, 9999999_999999999L, 99999999_999999999L,
999999999_999999999L, Long.MAX_VALUE
};

public static final byte[] MIN_INTEGER_VALUE = String.valueOf(Integer.MIN_VALUE).getBytes(US_ASCII);
public static final byte[] MIN_LONG_VALUE = String.valueOf(Long.MIN_VALUE).getBytes(US_ASCII);
public static final byte MINUS_SIGN = (byte)'-';
Expand Down
69 changes: 35 additions & 34 deletions agrona/src/main/java/org/agrona/ExpandableArrayBuffer.java
Original file line number Diff line number Diff line change
Expand Up @@ -803,90 +803,91 @@ public int wrapAdjustment()

///////////////////////////////////////////////////////////////////////////

public int parseNaturalIntAscii(final int start, final int length)
public int parseNaturalIntAscii(final int index, final int length)
{
boundsCheck0(start, length);
boundsCheck0(index, length);

final int end = start + length;
final int end = index + length;
int tally = 0;
for (int index = start; index < end; index++)
for (int i = index; i < end; i++)
{
tally = (tally * 10) + getDigit(index);
tally = (tally * 10) + getDigit(i);
}

return tally;
}

public long parseNaturalLongAscii(final int start, final int length)
public long parseNaturalLongAscii(final int index, final int length)
{
boundsCheck0(start, length);
boundsCheck0(index, length);

final int end = start + length;
final int end = index + length;
long tally = 0;
for (int index = start; index < end; index++)
for (int i = index; i < end; i++)
{
tally = (tally * 10) + getDigit(index);
tally = (tally * 10) + getDigit(i);
}

return tally;
}

public int parseIntAscii(final int start, final int length)
public int parseIntAscii(final int index, final int length)
{
boundsCheck0(start, length);
boundsCheck0(index, length);

final int endExclusive = start + length;
final int first = getByte(start);
int index = start;
if (first == NEGATIVE)
final int endExclusive = index + length;
final int first = getByte(index);
int i = index;

if (first == MINUS_SIGN)
{
index++;
i++;
}

int tally = 0;
for (; index < endExclusive; index++)
for (; i < endExclusive; i++)
{
tally = (tally * 10) + getDigit(index);
tally = (tally * 10) + getDigit(i);
}

if (first == NEGATIVE)
if (first == MINUS_SIGN)
{
tally *= -1;
tally = -tally;
}

return tally;
}

public long parseLongAscii(final int start, final int length)
public long parseLongAscii(final int index, final int length)
{
boundsCheck0(start, length);
boundsCheck0(index, length);

final int endExclusive = index + length;
final int first = getByte(index);
int i = index;

final int endExclusive = start + length;
final int first = getByte(start);
int index = start;
if (first == NEGATIVE)
if (first == MINUS_SIGN)
{
index++;
i++;
}

long tally = 0;
for (; index < endExclusive; index++)
for (; i < endExclusive; i++)
{
tally = (tally * 10) + getDigit(index);
tally = (tally * 10) + getDigit(i);
}

if (first == NEGATIVE)
if (first == MINUS_SIGN)
{
tally *= -1;
tally = -tally;
}

return tally;
}

private int getDigit(final int index)
{
final byte value = getByte(index);
return AsciiEncodingHelper.getDigit(index, value);
return AsciiEncodingHelper.getDigit(index, byteArray[index]);
}

public int putIntAscii(final int index, final int value)
Expand Down
64 changes: 32 additions & 32 deletions agrona/src/main/java/org/agrona/ExpandableDirectByteBuffer.java
Original file line number Diff line number Diff line change
Expand Up @@ -237,81 +237,81 @@ public int getInt(final int index)
return UNSAFE.getInt(null, address + index);
}

public int parseNaturalIntAscii(final int start, final int length)
public int parseNaturalIntAscii(final int index, final int length)
{
boundsCheck0(start, length);
boundsCheck0(index, length);

final int end = start + length;
final int end = index + length;
int tally = 0;
for (int index = start; index < end; index++)
for (int i = index; i < end; i++)
{
tally = (tally * 10) + getDigit(index);
tally = (tally * 10) + getDigit(i);
}

return tally;
}

public long parseNaturalLongAscii(final int start, final int length)
public long parseNaturalLongAscii(final int index, final int length)
{
boundsCheck0(start, length);
boundsCheck0(index, length);

final int end = start + length;
final int end = index + length;
long tally = 0L;
for (int index = start; index < end; index++)
for (int i = index; i < end; i++)
{
tally = (tally * 10) + getDigit(index);
tally = (tally * 10) + getDigit(i);
}

return tally;
}

public int parseIntAscii(final int start, final int length)
public int parseIntAscii(final int index, final int length)
{
boundsCheck0(start, length);
boundsCheck0(index, length);

final int endExclusive = start + length;
final int first = getByte(start);
int index = start;
if (first == NEGATIVE)
final int endExclusive = index + length;
final int first = getByte(index);
int i = index;
if (first == MINUS_SIGN)
{
index++;
i++;
}

int tally = 0;
for (; index < endExclusive; index++)
for (; i < endExclusive; i++)
{
tally = (tally * 10) + getDigit(index);
tally = (tally * 10) + getDigit(i);
}

if (first == NEGATIVE)
if (first == MINUS_SIGN)
{
tally *= -1;
tally = -tally;
}

return tally;
}

public long parseLongAscii(final int start, final int length)
public long parseLongAscii(final int index, final int length)
{
boundsCheck0(start, length);
boundsCheck0(index, length);

final int endExclusive = start + length;
final int first = getByte(start);
int index = start;
if (first == NEGATIVE)
final int endExclusive = index + length;
final int first = getByte(index);
int i = index;
if (first == MINUS_SIGN)
{
index++;
i++;
}

long tally = 0;
for (; index < endExclusive; index++)
for (; i < endExclusive; i++)
{
tally = (tally * 10) + getDigit(index);
tally = (tally * 10) + getDigit(i);
}

if (first == NEGATIVE)
if (first == MINUS_SIGN)
{
tally *= -1;
tally = -tally;
}

return tally;
Expand Down
69 changes: 35 additions & 34 deletions agrona/src/main/java/org/agrona/concurrent/UnsafeBuffer.java
Original file line number Diff line number Diff line change
Expand Up @@ -1364,102 +1364,103 @@ public int wrapAdjustment()

///////////////////////////////////////////////////////////////////////////

public int parseNaturalIntAscii(final int start, final int length)
public int parseNaturalIntAscii(final int index, final int length)
{
if (SHOULD_BOUNDS_CHECK)
{
boundsCheck0(start, length);
boundsCheck0(index, length);
}

final int end = start + length;
final int end = index + length;
int tally = 0;
for (int index = start; index < end; index++)
for (int i = index; i < end; i++)
{
tally = (tally * 10) + getDigit(index);
tally = (tally * 10) + getDigit(i);
}

return tally;
}

public long parseNaturalLongAscii(final int start, final int length)
public long parseNaturalLongAscii(final int index, final int length)
{
if (SHOULD_BOUNDS_CHECK)
{
boundsCheck0(start, length);
boundsCheck0(index, length);
}

final int end = start + length;
final int end = index + length;
long tally = 0;
for (int index = start; index < end; index++)
for (int i = index; i < end; i++)
{
tally = (tally * 10) + getDigit(index);
tally = (tally * 10) + getDigit(i);
}

return tally;
}

public int parseIntAscii(final int start, final int length)
public int parseIntAscii(final int index, final int length)
{
if (SHOULD_BOUNDS_CHECK)
{
boundsCheck0(start, length);
boundsCheck0(index, length);
}

final int endExclusive = start + length;
final int first = getByteWithoutBoundsCheck(start);
int index = start;
if (first == NEGATIVE)
final int endExclusive = index + length;
final int first = getByteWithoutBoundsCheck(index);
int i = index;

if (first == MINUS_SIGN)
{
index++;
i++;
}

int tally = 0;
for (; index < endExclusive; index++)
for (; i < endExclusive; i++)
{
tally = (tally * 10) + getDigit(index);
tally = (tally * 10) + getDigit(i);
}

if (first == NEGATIVE)
if (first == MINUS_SIGN)
{
tally *= -1;
tally = -tally;
}

return tally;
}

public long parseLongAscii(final int start, final int length)
public long parseLongAscii(final int index, final int length)
{
if (SHOULD_BOUNDS_CHECK)
{
boundsCheck0(start, length);
boundsCheck0(index, length);
}

final int endExclusive = start + length;
final int first = getByteWithoutBoundsCheck(start);
int index = start;
if (first == NEGATIVE)
final int endExclusive = index + length;
final int first = getByteWithoutBoundsCheck(index);
int i = index;

if (first == MINUS_SIGN)
{
index++;
i++;
}

long tally = 0;
for (; index < endExclusive; index++)
for (; i < endExclusive; i++)
{
tally = (tally * 10) + getDigit(index);
tally = (tally * 10) + getDigit(i);
}

if (first == NEGATIVE)
if (first == MINUS_SIGN)
{
tally *= -1;
tally = -tally;
}

return tally;
}

private int getDigit(final int index)
{
final byte value = getByteWithoutBoundsCheck(index);
return AsciiEncodingHelper.getDigit(index, value);
return AsciiEncodingHelper.getDigit(index, getByteWithoutBoundsCheck(index));
}

public int putIntAscii(final int index, final int value)
Expand Down
Loading

0 comments on commit 3a0169a

Please sign in to comment.