Skip to content

Commit

Permalink
One lgtm.com suggestion
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder committed Jan 7, 2021
1 parent 49223ee commit 78d096a
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1516,14 +1516,14 @@ private final String _decodeLongUnicodeName(int[] quads, int byteLen, int quadLe
{
int lastQuadBytes = byteLen & 3;
// Ok: must decode UTF-8 chars. No other validation SHOULD be needed (except bounds checks?)
/* Note: last quad is not correctly aligned (leading zero bytes instead
* need to shift a bit, instead of trailing). Only need to shift it
* for UTF-8 decoding; need revert for storage (since key will not
* be aligned, to optimize lookup speed)
*/

// Note: last quad is not correctly aligned (leading zero bytes instead
// need to shift a bit, instead of trailing). Only need to shift it
// for UTF-8 decoding; need revert for storage (since key will not
// be aligned, to optimize lookup speed)
//
int lastQuad;

if (lastQuadBytes < 4) {
if (lastQuadBytes > 0) {
lastQuad = quads[quadLen-1];
// 8/16/24 bit left shift
quads[quadLen-1] = (lastQuad << ((4 - lastQuadBytes) << 3));
Expand Down Expand Up @@ -1574,7 +1574,7 @@ private final String _decodeLongUnicodeName(int[] quads, int byteLen, int quadLe
byteIx = (ix & 3);
ch2 = (ch2 >> ((3 - byteIx) << 3));
++ix;

if ((ch2 & 0xC0) != 0x080) {
_reportInvalidOther(ch2);
}
Expand Down Expand Up @@ -1608,7 +1608,7 @@ private final String _decodeLongUnicodeName(int[] quads, int byteLen, int quadLe
// Ok. Now we have the character array, and can construct the String
String baseName = new String(cbuf, 0, cix);
// And finally, un-align if necessary
if (lastQuadBytes < 4) {
if (lastQuadBytes > 0) {
quads[quadLen-1] = lastQuad;
}
return _symbols.addName(baseName, quads, quadLen);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,21 @@ public void testSharedNameSimple() throws Exception

// same as above, but with name >= 64 characters
public void testSharedNameSimpleLong() throws Exception
{
_testSharedNameSimpleLong("ABCD");
_testSharedNameSimpleLong("ABCY");
_testSharedNameSimpleLong("XBCD");
_testSharedNameSimpleLong("ACCD");
}

private void _testSharedNameSimpleLong(String suffix) throws Exception
{
String digits = "01234567899";

// Base is 76 chars; loop over couple of shorter ones too

final String LONG_NAME = "a"+digits+"b"+digits+"c"+digits+"d"+digits+"e"+digits+"f"+digits+"ABCD";
final String LONG_NAME = "a"+digits+"b"+digits+"c"+digits+"d"+digits+"e"+digits+"f"+digits+suffix;

for (int i = 0; i < 4; ++i) {
int strLen = LONG_NAME.length() - i;
String field = LONG_NAME.substring(0, strLen);
Expand All @@ -64,14 +72,14 @@ public void testSharedNameSimpleLong() throws Exception

assertToken(JsonToken.START_OBJECT, parser.nextToken());
assertToken(JsonToken.FIELD_NAME, parser.nextToken());
assertEquals(field, parser.getCurrentName());
assertEquals(field, parser.currentName());
assertToken(JsonToken.VALUE_NUMBER_INT, parser.nextToken());
assertEquals(1, parser.getIntValue());
assertToken(JsonToken.END_OBJECT, parser.nextToken());

assertToken(JsonToken.START_OBJECT, parser.nextToken());
assertToken(JsonToken.FIELD_NAME, parser.nextToken());
assertEquals(field, parser.getCurrentName());
assertEquals(field, parser.currentName());
assertToken(JsonToken.VALUE_NUMBER_INT, parser.nextToken());
assertEquals(2, parser.getIntValue());
assertToken(JsonToken.END_OBJECT, parser.nextToken());
Expand Down Expand Up @@ -217,13 +225,13 @@ public void _testLongNames(boolean shareNames) throws Exception
gen.close();

JsonParser parser = factory.createParser(os.toByteArray());
assertNull(parser.getCurrentToken());
assertNull(parser.currentToken());
assertToken(JsonToken.START_OBJECT, parser.nextToken());
assertToken(JsonToken.FIELD_NAME, parser.nextToken());
assertEquals("query", parser.getCurrentName());
assertEquals("query", parser.currentName());
assertToken(JsonToken.START_OBJECT, parser.nextToken());
assertToken(JsonToken.FIELD_NAME, parser.nextToken());
assertEquals(FIELD_NAME, parser.getCurrentName());
assertEquals(FIELD_NAME, parser.currentName());
assertToken(JsonToken.VALUE_STRING, parser.nextToken());
assertEquals(VALUE, parser.getText());
assertToken(JsonToken.END_OBJECT, parser.nextToken());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public void testLongNames() throws IOException
{
_testWithName(generateName(5000));
}

public void testJsonBinForLargeObjects() throws Exception
{
StringBuilder nameBuf = new StringBuilder("longString");
Expand All @@ -30,7 +30,7 @@ public void testJsonBinForLargeObjects() throws Exception
/* Helper methods
/**********************************************************
*/

private void _testWithName(String name) throws IOException
{
byte[] data = _smileDoc("{"+quote(name)+":13}");
Expand Down

0 comments on commit 78d096a

Please sign in to comment.