提交 bf9a900b 编写于 作者: W wenshao

improved performance.

上级 ee614b6e
......@@ -302,11 +302,12 @@ public class JSONArray extends JSON implements List<Object>, Cloneable, RandomAc
public byte getByteValue(int index) {
Object value = get(index);
if (value == null) {
Byte byteVal = castToByte(value);
if (byteVal == null) {
return 0;
}
return castToByte(value).byteValue();
return byteVal.byteValue();
}
public Short getShort(int index) {
......@@ -318,11 +319,12 @@ public class JSONArray extends JSON implements List<Object>, Cloneable, RandomAc
public short getShortValue(int index) {
Object value = get(index);
if (value == null) {
Short shortVal = castToShort(value);
if (shortVal == null) {
return 0;
}
return castToShort(value).shortValue();
return shortVal.shortValue();
}
public Integer getInteger(int index) {
......@@ -334,11 +336,12 @@ public class JSONArray extends JSON implements List<Object>, Cloneable, RandomAc
public int getIntValue(int index) {
Object value = get(index);
if (value == null) {
Integer intVal = castToInt(value);
if (intVal == null) {
return 0;
}
return castToInt(value).intValue();
return intVal.intValue();
}
public Long getLong(int index) {
......@@ -350,11 +353,12 @@ public class JSONArray extends JSON implements List<Object>, Cloneable, RandomAc
public long getLongValue(int index) {
Object value = get(index);
if (value == null) {
Long longVal = castToLong(value);
if (longVal == null) {
return 0L;
}
return castToLong(value).longValue();
return longVal.longValue();
}
public Float getFloat(int index) {
......@@ -366,11 +370,12 @@ public class JSONArray extends JSON implements List<Object>, Cloneable, RandomAc
public float getFloatValue(int index) {
Object value = get(index);
if (value == null) {
Float floatValue = castToFloat(value);
if (floatValue == null) {
return 0F;
}
return castToFloat(value).floatValue();
return floatValue.floatValue();
}
public Double getDouble(int index) {
......@@ -382,11 +387,12 @@ public class JSONArray extends JSON implements List<Object>, Cloneable, RandomAc
public double getDoubleValue(int index) {
Object value = get(index);
if (value == null) {
Double doubleValue = castToDouble(value);
if (doubleValue == null) {
return 0D;
}
return castToDouble(value);
return doubleValue.doubleValue();
}
public BigDecimal getBigDecimal(int index) {
......
......@@ -782,8 +782,10 @@ public class JSONPath implements JSONAware {
}
if (isInt(startValue.getClass()) && isInt(endValue.getClass())) {
Filter filter = new IntBetweenSegement(propertyName, ((Number) startValue).longValue(),
((Number) endValue).longValue(), not);
Filter filter = new IntBetweenSegement(propertyName
, TypeUtils.longExtractValue((Number) startValue)
, TypeUtils.longExtractValue((Number) endValue)
, not);
return filter;
}
......@@ -864,7 +866,7 @@ public class JSONPath implements JSONAware {
if (isInt) {
if (valueList.size() == 1) {
long value = ((Number) valueList.get(0)).longValue();
long value = TypeUtils.longExtractValue((Number) valueList.get(0));
Operator intOp = not ? Operator.NE : Operator.EQ;
Filter filter = new IntOpSegement(propertyName, value, intOp);
while (ch == ' ') {
......@@ -889,7 +891,7 @@ public class JSONPath implements JSONAware {
long[] values = new long[valueList.size()];
for (int i = 0; i < values.length; ++i) {
values[i] = ((Number) valueList.get(i)).longValue();
values[i] = TypeUtils.longExtractValue((Number) valueList.get(i));
}
Filter filter = new IntInSegement(propertyName, values, not);
......@@ -971,7 +973,7 @@ public class JSONPath implements JSONAware {
for (int i = 0; i < values.length; ++i) {
Number item = (Number) valueList.get(i);
if (item != null) {
values[i] = item.longValue();
values[i] = TypeUtils.longExtractValue(item);
}
}
......@@ -1847,7 +1849,7 @@ public class JSONPath implements JSONAware {
}
if (propertyValue instanceof Number) {
long longPropertyValue = ((Number) propertyValue).longValue();
long longPropertyValue = TypeUtils.longExtractValue((Number) propertyValue);
for (long value : values) {
if (value == longPropertyValue) {
return !not;
......@@ -1883,7 +1885,7 @@ public class JSONPath implements JSONAware {
}
if (propertyValue instanceof Number) {
long longPropertyValue = ((Number) propertyValue).longValue();
long longPropertyValue = TypeUtils.longExtractValue((Number) propertyValue);
if (longPropertyValue >= startValue && longPropertyValue <= endValue) {
return !not;
}
......@@ -1921,7 +1923,7 @@ public class JSONPath implements JSONAware {
}
if (propertyValue instanceof Number) {
long longPropertyValue = ((Number) propertyValue).longValue();
long longPropertyValue = TypeUtils.longExtractValue((Number) propertyValue);
for (Long value : values) {
if (value == null) {
continue;
......@@ -2067,7 +2069,7 @@ public class JSONPath implements JSONAware {
return false;
}
long longValue = ((Number) propertyValue).longValue();
long longValue = TypeUtils.longExtractValue((Number) propertyValue);
switch (op) {
case EQ:
......@@ -2547,7 +2549,7 @@ public class JSONPath implements JSONAware {
BigDecimal decimalA = (BigDecimal) a;
if (isIntB) {
return decimalA.equals(BigDecimal.valueOf(b.longValue()));
return decimalA.equals(BigDecimal.valueOf(TypeUtils.longExtractValue(b)));
}
}
......@@ -2567,7 +2569,7 @@ public class JSONPath implements JSONAware {
if (isIntB) {
if (a instanceof BigInteger) {
BigInteger bigIntA = (BigInteger) a;
BigInteger bigIntB = BigInteger.valueOf(b.longValue());
BigInteger bigIntB = BigInteger.valueOf(TypeUtils.longExtractValue(b));
return bigIntA.equals(bigIntB);
}
......
......@@ -1420,7 +1420,7 @@ public class DefaultJSONParser implements Closeable {
lexer.nextToken(JSONToken.LPAREN);
accept(JSONToken.LPAREN);
long time = ((Number) lexer.integerValue()).longValue();
long time = lexer.integerValue().longValue();
accept(JSONToken.LITERAL_INT);
accept(JSONToken.RPAREN);
......
package com.alibaba.fastjson.parser.deserializer;
import java.lang.reflect.Type;
import java.math.BigDecimal;
import com.alibaba.fastjson.JSONException;
import com.alibaba.fastjson.parser.DefaultJSONParser;
......@@ -47,6 +48,8 @@ public class TimeDeserializer implements ObjectDeserializer {
if (val instanceof java.sql.Time) {
return (T) val;
} else if (val instanceof BigDecimal) {
return (T) new java.sql.Time(((BigDecimal) val).longValueExact());
} else if (val instanceof Number) {
return (T) new java.sql.Time(((Number) val).longValue());
} else if (val instanceof String) {
......
......@@ -727,7 +727,8 @@ public class IOUtils {
if (((b2 & 0xc0) != 0x80 || (b3 & 0xc0) != 0x80 || (b4 & 0xc0) != 0x80) // isMalformed4
||
// shortest form check
!Character.isSupplementaryCodePoint(uc)) {
!(uc >= 0x010000 && uc < 0X10FFFF + 1) // !Character.isSupplementaryCodePoint(uc)
) {
return -1;
} else {
da[dp++] = (char) ((uc >>> 10) + ('\uD800' - (0x010000 >>> 10))); // Character.highSurrogate(uc);
......
......@@ -458,6 +458,14 @@ public class TypeUtils{
return new java.sql.Date(longValue);
}
public static long longExtractValue(Number number) {
if (number instanceof BigDecimal) {
return ((BigDecimal) number).longValueExact();
}
return number.longValue();
}
public static java.sql.Time castToSqlTime(Object value){
if(value == null){
return null;
......@@ -471,10 +479,14 @@ public class TypeUtils{
if(value instanceof Calendar){
return new java.sql.Time(((Calendar) value).getTimeInMillis());
}
long longValue = 0;
if(value instanceof Number){
if(value instanceof BigDecimal){
longValue = ((BigDecimal) value).longValueExact();
} else if(value instanceof Number){
longValue = ((Number) value).longValue();
}
if(value instanceof String){
String strVal = (String) value;
if(strVal.length() == 0 //
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册