Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
wenshao committed Jan 8, 2023
1 parent 502d398 commit 57aebf9
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2687,7 +2687,8 @@ public String readFieldName() {
symbol0Length = strlen;
symbol0StrType = strtype;
} else {
int minCapacity = symbol * 2 + 2;
int symbolIndex = symbol * 2 + 2;
int minCapacity = symbolIndex;
if (symbols == null) {
symbols = new long[minCapacity < 32 ? 32 : minCapacity];
} else if (symbols.length < minCapacity) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -455,15 +455,16 @@ public long readFieldNameHashCode() {

long strInfo = ((long) strBegin << 32) + ((long) strlen << 8) + strtype;

int minCapacity = symbol * 2 + 2;
int symbolIndex = symbol * 2;
int minCapacity = symbolIndex + 2;
if (symbols == null) {
symbols = new long[minCapacity < 32 ? 32 : minCapacity];
} else if (symbols.length < minCapacity) {
symbols = Arrays.copyOf(symbols, minCapacity + 16);
}

symbols[symbol * 2] = hashCode;
symbols[symbol * 2 + 1] = strInfo;
symbols[symbolIndex] = hashCode;
symbols[symbolIndex + 1] = strInfo;
}

return hashCode;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.alibaba.fastjson2.JSONReader;
import org.junit.jupiter.api.Test;

import java.util.ArrayList;
import java.util.List;

public class Hello {
Expand All @@ -13,7 +14,9 @@ public void test() throws Exception {
System.out.println("java.vm.name : " + jmvName);

User user = new User(1, "雷卷");
String jsonText = JSON.toJSONString(List.of(user));
List list = new ArrayList();
list.add(user);
String jsonText = JSON.toJSONString(list);
List<User> user2 = JSON.parseArray(jsonText, User.class);
System.out.println(jsonText);
System.out.println("Fastjson: " + user2.get(0).getNick());
Expand Down

0 comments on commit 57aebf9

Please sign in to comment.