Comments (6)
另外一个思路做法是
通过编译过程(如编译插件)来完(一些)成手动做的内联动作。
from fastjson2.
合并重复代码还是谨慎一些。你想合并哪些?可以提一个上来看看
from fastjson2.
合并重复代码还是谨慎一些。你想合并哪些?可以提一个上来看看
我的意思不是合并重复代码, 而是对重复的代码在它所在方法上优化改动, 比如
JSONReaderASCII.java#L718
if (b == ',') {
this.offset = offset + 1;
// inline next
ch = (char) bytes[this.offset++];
while (ch <= ' ' && ((1L << ch) & SPACE) != 0) {
if (this.offset >= end) {
ch = EOI;
} else {
ch = (char) bytes[this.offset++];
}
}
} else {
this.offset = offset + 1;
this.ch = (char) b;
}
中 this.offset = offset + 1;
完全可以提前, 不用重复.
_for:
for (int i = 0; ; ++i) {
byte c = bytes[offset];
if (c == '\\') {
valueEscape = true;
c = bytes[++offset];
switch (c) {
case 'u': {
offset += 4;
break;
}
case 'x': {
offset += 2;
break;
}
default:
// skip
break;
}
offset++;
continue;
}
if (c == quote) {
valueLength = i;
break _for;
}
offset++;
}
可以把 break _for;
优化为 break;
从而 _for
label 可以去掉, 这里的 _for
label 在很多地方都内联导致重复.
} else if (ch >= '\uD800' && ch < ('\uDFFF' + 1)) { // //Character.isSurrogate(c)
final int uc;
if (ch >= '\uD800' && ch < ('\uDBFF' + 1)) { // Character.isHighSurrogate(c)
if (chars.length - i < 2) {
uc = -1;
} else {
char d = chars[i + 1];
// d >= '\uDC00' && d < ('\uDFFF' + 1)
if (d >= '\uDC00' && d < ('\uDFFF' + 1)) { // Character.isLowSurrogate(d)
uc = ((ch << 10) + d) + (0x010000 - ('\uD800' << 10) - '\uDC00'); // Character.toCodePoint(c, d)
} else {
// throw new JSONException("encodeUTF8 error", new MalformedInputException(1));
bytes[off++] = (byte) '?';
continue;
}
}
} else {
//
if (ch >= '\uDC00' && ch < ('\uDFFF' + 1)) { // Character.isLowSurrogate(c)
bytes[off++] = (byte) '?';
continue;
// throw new JSONException("encodeUTF8 error", new MalformedInputException(1));
} else {
uc = ch;
}
}
if (uc < 0) {
bytes[off++] = (byte) '?';
} else {
bytes[off++] = (byte) (0xf0 | ((uc >> 18)));
bytes[off++] = (byte) (0x80 | ((uc >> 12) & 0x3f));
bytes[off++] = (byte) (0x80 | ((uc >> 6) & 0x3f));
bytes[off++] = (byte) (0x80 | (uc & 0x3f));
i++; // 2 chars
}
这里的 ch >= '\uD800'
重复判断, uc = -1;
这里可以直接 continue;
, 这里编码部分很多地方都有内联一样代码, 都是是可以优化.
我的疑惑是: 是否为了内联代码一致, 而不根据代码所在的环境下优化变动.
from fastjson2.
应该要根据所在环境进行优化,造成现状是因为手工内联的时候,没有做完根据上下文优化的事情,看到就提PR改进吧。
from fastjson2.
另外一个思路做法是 通过编译过程(如编译插件)来完(一些)成手动做的内联动作。
我也赞同您的观点, 通过编译时内联, 省去手工也还可以保障代码一致
from fastjson2.
应该要根据所在环境进行优化,造成现状是因为手工内联的时候,没有做完根据上下文优化的事情,看到就提PR改进吧。
好的谢谢温少, 我明白了您的观点。
from fastjson2.
Related Issues (20)
- 解析json字符串时,取消unicode自动解码 HOT 2
- [QUESTION] 單字段的 parsing 方式 HOT 1
- Date格式反序列化异常 HOT 3
- JSONPath.eval方法对于数组,列表格式的路径解析与1.X的输出结果不一致 HOT 1
- fastjson从1.2.83升级到兼容版本2.0.39序列化ChannelSftp导致后续sftp命令无法执行 HOT 5
- [BUG]类似于java.sql.Struct类型数据返回内存溢出,建议优化处理 HOT 3
- [BUG] 序列化LocalDateTime字段时报错 HOT 5
- [FEATURE] 引用检测开关(ReferenceDetection)生成的引用路径否应该使用兼容性更好的 $['key'] 👀 而不是 $.key HOT 2
- [BUG]国产鲲鹏服务器会出现com.alibaba.fastjson2.JSONException: syntax error : f(目前观察结果是不稳定,不能每次复现) HOT 7
- 反馈问题:当 Double 字段为 null时。开启 WriteNullNumberAsZero 和 WriteLongAsString,会变成 "0" HOT 7
- SpringMvc中全局设置了`JSONWriter.Feature.WriteMapNullValue`,如何单独指定某个类型设置不过滤NULL(也就是fastjson)默认序列化方式 HOT 15
- 在字段上使用JSONField注解中的deserializeUsing、serializeUsing无效不起作用。 HOT 4
- [QUESTION]如何在自定义序列化时实现某条件满足时忽略该字段的序列化 HOT 3
- [BUG] Parcelable 序列化以后的类,转换成json格式,多了一个{"stability":0}}字段 HOT 2
- [FEATURE] 请问是否有考虑支持JSONQuery? HOT 1
- [FEATURE] 兼容jackson的序列化/反序列化注解 HOT 1
- [FEATURE] 不同类集合间的复制实现 HOT 1
- 后台返回出现JSON前边乱码请问怎么解决 HOT 5
- [BUG] 将localdatetime put到jsonobject,再次输出时候T不见了 HOT 2
- [BUG]JSON.isValid()方法抛出了异常 HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from fastjson2.