enjoy 3.5
This commit is contained in:
@@ -18,13 +18,14 @@ package com.jfinal.template.expr.ast;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.HashMap;
|
||||
import com.jfinal.kit.SyncWriteMap;
|
||||
|
||||
/**
|
||||
* FieldKit
|
||||
*/
|
||||
public class FieldKit {
|
||||
|
||||
private static final HashMap<Long, Object> fieldCache = new HashMap<Long, Object>();
|
||||
private static final HashMap<Long, Object> fieldCache = new SyncWriteMap<Long, Object>(512, 0.5F);
|
||||
|
||||
public static Field getField(Long key, Class<?> targetClass, String fieldName) {
|
||||
Object field = fieldCache.get(key);
|
||||
|
@@ -24,6 +24,17 @@ import com.jfinal.template.stat.Scope;
|
||||
|
||||
/**
|
||||
* Method : expr '.' ID '(' exprList? ')'
|
||||
*
|
||||
* 每次通过 MethodKit.getMethod(...) 取 MethodInfo 而不是用属性持有其对象
|
||||
* 是为了支持 target 对象的动态类型,MethodInfo 中的 Method 被调用 15 次以后
|
||||
* 会被 JDK 动态生成 GeneratedAccessorXXX 字节码,性能不是问题
|
||||
* 唯一的性能损耗是从 HashMap 中获取 MethodInfo 对象,可以忽略不计
|
||||
*
|
||||
* 如果在未来通过结合 #dynamic(boolean) 指令来优化,需要在 Ctrl 中引入一个
|
||||
* boolean dynamic = false 变量,而不能在 Env、Scope 引入该变量
|
||||
*
|
||||
* 还需要引入一个 NullMethodInfo 以及 isNull() 方法,此优化复杂度提高不少,
|
||||
* 暂时不做此优化
|
||||
*/
|
||||
public class Method extends Expr {
|
||||
|
||||
|
@@ -23,6 +23,7 @@ import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import com.jfinal.kit.ReflectKit;
|
||||
import com.jfinal.kit.SyncWriteMap;
|
||||
import com.jfinal.template.ext.extensionmethod.ByteExt;
|
||||
import com.jfinal.template.ext.extensionmethod.DoubleExt;
|
||||
import com.jfinal.template.ext.extensionmethod.FloatExt;
|
||||
@@ -37,10 +38,10 @@ import com.jfinal.template.ext.extensionmethod.StringExt;
|
||||
public class MethodKit {
|
||||
|
||||
private static final Class<?>[] NULL_ARG_TYPES = new Class<?>[0];
|
||||
private static final Set<String> forbiddenMethods = new HashSet<String>();
|
||||
private static final Set<Class<?>> forbiddenClasses = new HashSet<Class<?>>();
|
||||
private static final Map<Class<?>, Class<?>> primitiveMap = new HashMap<Class<?>, Class<?>>();
|
||||
private static final HashMap<Long, Object> methodCache = new HashMap<Long, Object>();
|
||||
private static final Set<String> forbiddenMethods = new HashSet<String>(64);
|
||||
private static final Set<Class<?>> forbiddenClasses = new HashSet<Class<?>>(64);
|
||||
private static final Map<Class<?>, Class<?>> primitiveMap = new HashMap<Class<?>, Class<?>>(64);
|
||||
private static final Map<Long, Object> methodCache = new SyncWriteMap<Long, Object>(2048, 0.25F);
|
||||
|
||||
// 初始化在模板中调用 method 时所在的被禁止使用类
|
||||
static {
|
||||
@@ -307,7 +308,7 @@ public class MethodKit {
|
||||
}
|
||||
}
|
||||
|
||||
private static final Map<Class<?>, Class<?>> primitiveToBoxedMap = new HashMap<Class<?>, Class<?>>();
|
||||
private static final Map<Class<?>, Class<?>> primitiveToBoxedMap = new HashMap<Class<?>, Class<?>>(64);
|
||||
|
||||
// 初始化 primitive type 到 boxed type 的映射
|
||||
static {
|
||||
|
@@ -27,6 +27,7 @@ import java.lang.reflect.Method;
|
||||
import java.lang.reflect.Modifier;
|
||||
import com.jfinal.kit.HashKit;
|
||||
import com.jfinal.kit.ReflectKit;
|
||||
import com.jfinal.kit.SyncWriteMap;
|
||||
|
||||
/**
|
||||
* SharedMethodKit
|
||||
@@ -44,7 +45,7 @@ public class SharedMethodKit {
|
||||
}
|
||||
|
||||
private final List<SharedMethodInfo> sharedMethodList = new ArrayList<SharedMethodInfo>();
|
||||
private final HashMap<Long, SharedMethodInfo> methodCache = new HashMap<Long, SharedMethodInfo>();
|
||||
private final HashMap<Long, SharedMethodInfo> methodCache = new SyncWriteMap<Long, SharedMethodInfo>(512, 0.25F);
|
||||
|
||||
public SharedMethodInfo getSharedMethodInfo(String methodName, Object[] argValues) {
|
||||
Class<?>[] argTypes = MethodKit.getArgTypes(argValues);
|
||||
|
Reference in New Issue
Block a user