Optimize method name exclusion using Set lookup instead of multiple equals checks

This commit is contained in:
AbhineshJha
2025-10-30 20:15:42 +05:30
parent fd1eee9c3b
commit f2acf8af69

View File

@@ -144,6 +144,18 @@ public class JSONObject {
*/ */
public static final Object NULL = new Null(); public static final Object NULL = new Null();
/**
* Set of method names that should be excluded when identifying record-style accessors.
* These are common bean/Object method names that are not property accessors.
*/
private static final Set<String> EXCLUDED_RECORD_METHOD_NAMES = Collections.unmodifiableSet(
new HashSet<String>(Arrays.asList(
"get", "is", "set",
"toString", "hashCode", "equals", "clone",
"notify", "notifyAll", "wait"
))
);
/** /**
* Construct an empty JSONObject. * Construct an empty JSONObject.
*/ */
@@ -1948,11 +1960,7 @@ public class JSONObject {
} }
// Exclude common bean/Object method names // Exclude common bean/Object method names
if ("get".equals(methodName) || "is".equals(methodName) || "set".equals(methodName) if (EXCLUDED_RECORD_METHOD_NAMES.contains(methodName)) {
|| "toString".equals(methodName) || "hashCode".equals(methodName)
|| "equals".equals(methodName) || "clone".equals(methodName)
|| "notify".equals(methodName) || "notifyAll".equals(methodName)
|| "wait".equals(methodName)) {
return false; return false;
} }