Skip to content

Commit

Permalink
Merge pull request #3176 from kang-hl/add-cache
Browse files Browse the repository at this point in the history
Cache generic param names
  • Loading branch information
harawata committed Jun 12, 2024
2 parents e836410 + 859a254 commit 9edc79a
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/main/java/org/apache/ibatis/reflection/ParamNameResolver.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2009-2023 the original author or authors.
* Copyright 2009-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -35,6 +35,14 @@ public class ParamNameResolver {

public static final String GENERIC_NAME_PREFIX = "param";

public static final String[] GENERIC_NAME_CACHE = new String[10];

static {
for (int i = 0; i < 10; i++) {
GENERIC_NAME_CACHE[i] = GENERIC_NAME_PREFIX + (i + 1);
}
}

private final boolean useActualParamName;

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

0 comments on commit 9edc79a

Please sign in to comment.