Skip to content

Commit

Permalink
升级0.0.13.1
Browse files Browse the repository at this point in the history
^ 优化及修复double解析可能潜在的bug;
^ 删除注释无用的代码;
  • Loading branch information
wycst committed Jun 12, 2024
1 parent f9a37df commit ca7ad23
Show file tree
Hide file tree
Showing 21 changed files with 948 additions and 1,153 deletions.
6 changes: 2 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<dependency>
<groupId>io.github.wycst</groupId>
<artifactId>wast</artifactId>
<version>0.0.13</version>
<version>0.0.13.1</version>
</dependency>
```

Expand Down Expand Up @@ -317,7 +317,6 @@ supports/json-springmvc/JSONHttpMessageConverter.java
| KeepOpenStream | 序列化后不关闭流,默认自动关闭流,开启后不会调用close |
| AllowUnquotedMapKey | 默认情况下map的key统一加双引号输出,开启后将根据实际的key值类型序列化 |
| UseFields | 默认通过实体类的getter方法序列化,开启后使用field字段进行序列化 |
| WriteDecimalUseToString | 默认浮点数的序列化使用科学计算法运算,启用配置可使用JDK内置的toString |

反序列化配置枚举类:ReadOption

Expand All @@ -329,8 +328,7 @@ supports/json-springmvc/JSONHttpMessageConverter.java
| AllowSingleQuotes | 非标准json特性:允许JSON字段的key使用单引号,注意仅仅是key |
| UnknownEnumAsNull | 不存在的枚举类型解析时默认抛出异常,开启后解析为null |
| UseDefaultFieldInstance | 解析实体bean的场景下,如果其属性的类型为普通抽象类或者接口(Map和Collection极其子类接口除外),如果指定了默认实例将使用默认实例对象,从使用上解决类型映射问题,而不用趟AutoType带来的各种安全漏洞的坑 |
| UseBigDecimalAsDefaultNumber | 开启后在不确定number类型情况下,统一转化为BigDecimal;默认自动判断number类型转化为int或long或者double |
| UseJDKDoubleParser | 默认的double解析模式通过科学计算法运算, 启用配置可使用JDK内置的API进行解析 |
| UseBigDecimalAsDefaultNumber | 开启后在不确定number类型情况下,统一转化为BigDecimal;默认自动判断number类型转化为int或long或者double | |
| AllowLastEndComma | 支持对象或者数组最后一个属性或者元素后面存在逗号,比如[1,2,3,]开启后也能正常解析 |
| UnMatchedEmptyAsNull | 解析到空字符串但目标类型又不是字符串时,返回null,否则抛出异常 |

Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<groupId>io.github.wycst</groupId>
<artifactId>wast</artifactId>
<version>0.0.13</version>
<version>0.0.13.1</version>
<modelVersion>4.0.0</modelVersion>
<packaging>jar</packaging>
<description>Wast is a high-performance Java toolset library package that includes JSON, YAML, CSV, HttpClient, JDBC and EL engines</description>
Expand Down
10 changes: 5 additions & 5 deletions src/main/java/io/github/wycst/wast/common/utils/ED5.java

Large diffs are not rendered by default.

21 changes: 21 additions & 0 deletions src/main/java/io/github/wycst/wast/common/utils/EnvUtils.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package io.github.wycst.wast.common.utils;

import io.github.wycst.wast.common.compiler.MemoryClassLoader;
import io.github.wycst.wast.common.reflect.UnsafeHelper;

import java.lang.reflect.Method;
Expand Down Expand Up @@ -45,6 +46,7 @@ public final class EnvUtils {
public static final Method SC_HAS_NEGATIVES_METHOD;
// public static final Method SL_INDEX_OF_METHOD;


static {
float jdkVersion = 1.8f;
try {
Expand Down Expand Up @@ -94,6 +96,25 @@ public final class EnvUtils {
// SL_INDEX_OF_METHOD = slIndexOfMethod;
}

public static final JdkApiAgent JDK_AGENT_INSTANCE;

static {
JdkApiAgent apiAgent = null;
if (EnvUtils.JDK_9_PLUS) {
try {
MemoryClassLoader memoryClassLoader = new MemoryClassLoader();
Class agentClass = memoryClassLoader.loadClass("io.github.wycst.wast.common.utils.JdkApiAgentJdk9Plus", ByteUtils.hexString2Bytes("CAFEBABE00000035001A0A000400140A001500160700170700180100063C696E69743E010003282956010004436F646501000F4C696E654E756D6265725461626C650100124C6F63616C5661726961626C655461626C65010004746869730100374C696F2F6769746875622F77796373742F776173742F636F6D6D6F6E2F7574696C732F4A646B4170694167656E744A646B39506C75733B01000C6D756C7469706C7948696768010005284A4A294A010001780100014A010001790100156D756C7469706C79486967684B617261747375626101000A536F7572636546696C650100184A646B4170694167656E744A646B39506C75732E6A6176610C000500060700190C000C000D010035696F2F6769746875622F77796373742F776173742F636F6D6D6F6E2F7574696C732F4A646B4170694167656E744A646B39506C757301002D696F2F6769746875622F77796373742F776173742F636F6D6D6F6E2F7574696C732F4A646B4170694167656E7401000E6A6176612F6C616E672F4D617468003100030004000000000003000100050006000100070000002F00010001000000052AB70001B10000000200080000000600010000000700090000000C000100000005000A000B00000001000C000D000100070000004400040005000000061F21B80002AD0000000200080000000600010000000A000900000020000300000006000A000B000000000006000E000F0001000000060010000F000300010011000D000100070000004400040005000000061F21B80002AD0000000200080000000600010000000E000900000020000300000006000A000B000000000006000E000F0001000000060010000F000300010012000000020013"));
apiAgent = (JdkApiAgent) UnsafeHelper.getUnsafe().allocateInstance(agentClass);
} catch (Throwable throwable) {
}
}
if (apiAgent == null) {
apiAgent = new JdkApiAgent() {
};
}
JDK_AGENT_INSTANCE = apiAgent;
}

private static Charset forCharsetName(String charsetName) {
try {
return Charset.forName(charsetName);
Expand Down
49 changes: 49 additions & 0 deletions src/main/java/io/github/wycst/wast/common/utils/JdkApiAgent.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package io.github.wycst.wast.common.utils;

/**
* @Date 2024/6/8 14:22
* @Created by wangyc
*/
public abstract class JdkApiAgent {

public long multiplyHigh(long x, long y) {
long x1 = x >> 32;
long x2 = x & 0xFFFFFFFFL;
long y1 = y >> 32;
long y2 = y & 0xFFFFFFFFL;

long z2 = x2 * y2;
long t = x1 * y2 + (z2 >>> 32);
long z1 = t & 0xFFFFFFFFL;
long z0 = t >> 32;
z1 += x2 * y1;
return x1 * y1 + z0 + (z1 >> 32);
}

public long unsignedMultiplyHigh(long x, long y) {
// Compute via multiplyHigh() to leverage the intrinsic
long result = multiplyHigh(x, y);
result += (y & (x >> 63));
result += (x & (y >> 63));
return result;
}

/**
* Calculate the high bits of two long values. To be compatible with performance below JDK9, please ensure that x and y are both greater than 0
*
* @param x > 0
* @param y > 0
* @return
*/
public long multiplyHighKaratsuba(long x, long y) {
long x1 = x >>> 32, x2 = x & 0xffffffffL;
long y1 = y >>> 32, y2 = y & 0xffffffffL;
long A = x1 * y1;
long B = x2 * y2;
long C = (x1 + x2) * (y1 + y2);
// karatsuba
long K = C - A - B;
long BC = B >>> 32;
return ((BC + K) >>> 32) + A;
}
}
Loading

0 comments on commit ca7ad23

Please sign in to comment.