Skip to content

Commit f2acf8a

Browse files
committed
Optimize method name exclusion using Set lookup instead of multiple equals checks
1 parent fd1eee9 commit f2acf8a

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

src/main/java/org/json/JSONObject.java

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,18 @@ public Class<? extends Map> getMapType() {
144144
*/
145145
public static final Object NULL = new Null();
146146

147+
/**
148+
* Set of method names that should be excluded when identifying record-style accessors.
149+
* These are common bean/Object method names that are not property accessors.
150+
*/
151+
private static final Set<String> EXCLUDED_RECORD_METHOD_NAMES = Collections.unmodifiableSet(
152+
new HashSet<String>(Arrays.asList(
153+
"get", "is", "set",
154+
"toString", "hashCode", "equals", "clone",
155+
"notify", "notifyAll", "wait"
156+
))
157+
);
158+
147159
/**
148160
* Construct an empty JSONObject.
149161
*/
@@ -1948,11 +1960,7 @@ private static boolean isRecordStyleAccessor(String methodName, Method method) {
19481960
}
19491961

19501962
// Exclude common bean/Object method names
1951-
if ("get".equals(methodName) || "is".equals(methodName) || "set".equals(methodName)
1952-
|| "toString".equals(methodName) || "hashCode".equals(methodName)
1953-
|| "equals".equals(methodName) || "clone".equals(methodName)
1954-
|| "notify".equals(methodName) || "notifyAll".equals(methodName)
1955-
|| "wait".equals(methodName)) {
1963+
if (EXCLUDED_RECORD_METHOD_NAMES.contains(methodName)) {
19561964
return false;
19571965
}
19581966

0 commit comments

Comments
 (0)