You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@groovy.apache.org by su...@apache.org on 2020/06/26 09:18:54 UTC
[groovy] branch master updated: Improve the performance of
`getPropertyName`
This is an automated email from the ASF dual-hosted git repository.
sunlan pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/groovy.git
The following commit(s) were added to refs/heads/master by this push:
new 47f74e3 Improve the performance of `getPropertyName`
47f74e3 is described below
commit 47f74e369d37fd52f0bb8d09f55596bff64f028d
Author: Daniel Sun <su...@apache.org>
AuthorDate: Fri Jun 26 17:18:33 2020 +0800
Improve the performance of `getPropertyName`
---
.../org/apache/groovy/ast/tools/MethodNodeUtils.java | 17 ++++++++++-------
1 file changed, 10 insertions(+), 7 deletions(-)
diff --git a/src/main/java/org/apache/groovy/ast/tools/MethodNodeUtils.java b/src/main/java/org/apache/groovy/ast/tools/MethodNodeUtils.java
index aa7cd3d..b553d71 100644
--- a/src/main/java/org/apache/groovy/ast/tools/MethodNodeUtils.java
+++ b/src/main/java/org/apache/groovy/ast/tools/MethodNodeUtils.java
@@ -78,16 +78,19 @@ public class MethodNodeUtils {
*/
public static String getPropertyName(MethodNode mNode) {
String name = mNode.getName();
- if (name.startsWith("set") || name.startsWith("get") || name.startsWith("is")) {
- String pname = decapitalize(name.substring(name.startsWith("is") ? 2 : 3));
- if (!pname.isEmpty()) {
- if (name.startsWith("set")) {
+ final boolean startsWithSet = name.startsWith("set");
+ final boolean startsWithGet = name.startsWith("get");
+ final boolean startsWithIs = name.startsWith("is");
+ if (startsWithGet || startsWithSet || startsWithIs) {
+ final String tmpPname = name.substring(startsWithIs ? 2 : 3);
+ if (!tmpPname.isEmpty()) {
+ if (startsWithSet) {
if (mNode.getParameters().length == 1) {
- return pname;
+ return decapitalize(tmpPname);
}
} else if (mNode.getParameters().length == 0 && !ClassHelper.VOID_TYPE.equals(mNode.getReturnType())) {
- if (name.startsWith("get") || ClassHelper.boolean_TYPE.equals(mNode.getReturnType())) {
- return pname;
+ if (startsWithGet || ClassHelper.boolean_TYPE.equals(mNode.getReturnType())) {
+ return decapitalize(tmpPname);
}
}
}