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 11:34:54 UTC
[groovy] 02/04: Improve the performance of `getPropertyName` further
This is an automated email from the ASF dual-hosted git repository.
sunlan pushed a commit to branch GROOVY_3_0_X
in repository https://gitbox.apache.org/repos/asf/groovy.git
commit 3a554f4ea38862b9813120fd47576991b32b8c1e
Author: Daniel Sun <su...@apache.org>
AuthorDate: Fri Jun 26 18:03:09 2020 +0800
Improve the performance of `getPropertyName` further
(cherry picked from commit 041a7e709ae005a3dec06cdeaf7d5f2e36c9f8cc)
---
.../java/org/apache/groovy/ast/tools/MethodNodeUtils.java | 13 +++++++++----
1 file changed, 9 insertions(+), 4 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 b553d71..1e2b9d8 100644
--- a/src/main/java/org/apache/groovy/ast/tools/MethodNodeUtils.java
+++ b/src/main/java/org/apache/groovy/ast/tools/MethodNodeUtils.java
@@ -77,11 +77,15 @@ public class MethodNodeUtils {
* @return the property name without the get/set/is prefix if a property or null
*/
public static String getPropertyName(MethodNode mNode) {
+ boolean startsWithGet = false;
+ boolean startsWithSet = false;
+ boolean startsWithIs = false;
String name = mNode.getName();
- final boolean startsWithSet = name.startsWith("set");
- final boolean startsWithGet = name.startsWith("get");
- final boolean startsWithIs = name.startsWith("is");
- if (startsWithGet || startsWithSet || startsWithIs) {
+
+ if ((startsWithGet = name.startsWith("get"))
+ || (startsWithSet = name.startsWith("set"))
+ || (startsWithIs = name.startsWith("is"))) {
+
final String tmpPname = name.substring(startsWithIs ? 2 : 3);
if (!tmpPname.isEmpty()) {
if (startsWithSet) {
@@ -95,6 +99,7 @@ public class MethodNodeUtils {
}
}
}
+
return null;
}