Skip to content

Commit 65b6592

Browse files
committed
refactor
1 parent a8cad71 commit 65b6592

File tree

2 files changed

+15
-50
lines changed

2 files changed

+15
-50
lines changed

src/main/java/com/alibaba/fastjson/parser/JSONLexerBase.java

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,9 @@
3434
import java.util.ArrayList;
3535
import java.util.Calendar;
3636
import java.util.Collection;
37+
import java.util.HashMap;
3738
import java.util.HashSet;
39+
import java.util.Map;
3840

3941
import com.alibaba.fastjson.JSON;
4042
import com.alibaba.fastjson.JSONException;
@@ -44,7 +46,18 @@
4446
* @author wenshao[szujobs@hotmail.com]
4547
*/
4648
public abstract class JSONLexerBase implements JSONLexer, Closeable {
49+
private final static Map<String, Integer> DEFAULT_KEYWORDS;
4750

51+
static {
52+
Map<String, Integer> map = new HashMap<String, Integer>();
53+
map.put("null", JSONToken.NULL);
54+
map.put("new", JSONToken.NEW);
55+
map.put("true", JSONToken.TRUE);
56+
map.put("false", JSONToken.FALSE);
57+
map.put("undefined", JSONToken.UNDEFINED);
58+
DEFAULT_KEYWORDS = map;
59+
}
60+
4861
protected void lexError(String key, Object... args) {
4962
token = ERROR;
5063
}
@@ -76,7 +89,7 @@ protected void lexError(String key, Object... args) {
7689
public int matchStat = UNKOWN;
7790

7891
private final static ThreadLocal<SoftReference<char[]>> SBUF_REF_LOCAL = new ThreadLocal<SoftReference<char[]>>();
79-
protected Keywords keywods = Keywords.DEFAULT_KEYWORDS;
92+
protected Map<String, Integer> keywods = DEFAULT_KEYWORDS;
8093

8194
public JSONLexerBase(){
8295
SoftReference<char[]> sbufRef = SBUF_REF_LOCAL.get();
@@ -2575,7 +2588,7 @@ public final void scanIdent() {
25752588

25762589
String ident = stringVal();
25772590

2578-
Integer tok = keywods.getKeyword(ident);
2591+
Integer tok = keywods.get(ident);
25792592
if (tok != null) {
25802593
token = tok;
25812594
} else {

src/main/java/com/alibaba/fastjson/parser/Keywords.java

Lines changed: 0 additions & 48 deletions
This file was deleted.

0 commit comments

Comments
 (0)