Skip to content

Commit a7eb236

Browse files
committed
Optimize method name exclusion using Set lookup instead of multiple equals checks
1 parent 01a8c28 commit a7eb236

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
@@ -141,6 +141,18 @@ public Class<? extends Map> getMapType() {
141141
*/
142142
public static final Object NULL = new Null();
143143

144+
/**
145+
* Set of method names that should be excluded when identifying record-style accessors.
146+
* These are common bean/Object method names that are not property accessors.
147+
*/
148+
private static final Set<String> EXCLUDED_RECORD_METHOD_NAMES = Collections.unmodifiableSet(
149+
new HashSet<String>(Arrays.asList(
150+
"get", "is", "set",
151+
"toString", "hashCode", "equals", "clone",
152+
"notify", "notifyAll", "wait"
153+
))
154+
);
155+
144156
/**
145157
* Construct an empty JSONObject.
146158
*/
@@ -1945,11 +1957,7 @@ private static boolean isRecordStyleAccessor(String methodName, Method method) {
19451957
}
19461958

19471959
// Exclude common bean/Object method names
1948-
if ("get".equals(methodName) || "is".equals(methodName) || "set".equals(methodName)
1949-
|| "toString".equals(methodName) || "hashCode".equals(methodName)
1950-
|| "equals".equals(methodName) || "clone".equals(methodName)
1951-
|| "notify".equals(methodName) || "notifyAll".equals(methodName)
1952-
|| "wait".equals(methodName)) {
1960+
if (EXCLUDED_RECORD_METHOD_NAMES.contains(methodName)) {
19531961
return false;
19541962
}
19551963

0 commit comments

Comments
 (0)