Skip to content

Commit 9edc79a

Browse files
authored
Merge pull request #3176 from kang-hl/add-cache
Cache generic param names
2 parents e836410 + 859a254 commit 9edc79a

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

src/main/java/org/apache/ibatis/reflection/ParamNameResolver.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2009-2023 the original author or authors.
2+
* Copyright 2009-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -35,6 +35,14 @@ public class ParamNameResolver {
3535

3636
public static final String GENERIC_NAME_PREFIX = "param";
3737

38+
public static final String[] GENERIC_NAME_CACHE = new String[10];
39+
40+
static {
41+
for (int i = 0; i < 10; i++) {
42+
GENERIC_NAME_CACHE[i] = GENERIC_NAME_PREFIX + (i + 1);
43+
}
44+
}
45+
3846
private final boolean useActualParamName;
3947

4048
/**
@@ -132,7 +140,7 @@ public Object getNamedParams(Object[] args) {
132140
for (Map.Entry<Integer, String> entry : names.entrySet()) {
133141
param.put(entry.getValue(), args[entry.getKey()]);
134142
// add generic param names (param1, param2, ...)
135-
final String genericParamName = GENERIC_NAME_PREFIX + (i + 1);
143+
final String genericParamName = i < 10 ? GENERIC_NAME_CACHE[i] : GENERIC_NAME_PREFIX + (i + 1);
136144
// ensure not to overwrite parameter named with @Param
137145
if (!names.containsValue(genericParamName)) {
138146
param.put(genericParamName, args[entry.getKey()]);

0 commit comments

Comments
 (0)