Skip to content

Conversation

@AlexCai2019
Copy link
Contributor

I found these 2 can be optimized during the last refactor.

  • Remove NULL.equals(object) in warp() method on line 2756 of JSONObject.java since line 2752 has already tested it.
  • Remove the empty string in readByIndexToken() method on line 249 of JSONPointer.java.

Remove "NULL.equals(object)" on line 2756 of JSONObject.java since line 2752 has already tested it.
Remove the empty string on line 249 of JSONPointer.java.
}
if (object instanceof JSONObject || object instanceof JSONArray
|| NULL.equals(object) || object instanceof JSONString
if (object instanceof JSONObject || object instanceof JSONArray || object instanceof JSONString
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

formatting

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@AlexCai2019 Please make this formatting change.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how should I do that?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if (    object instanceof JSONObject || object instanceof JSONArray
     || object instanceof JSONString || object instanceof Byte
     || object instanceof Character || object instanceof Short
     || object instanceof Integer   || object instanceof Long
     || object instanceof Boolean   || object instanceof Float
     || object instanceof Double    || object instanceof String
     || object instanceof BigInteger|| object instanceof BigDecimal
     || object instanceof Enum) {

    return object;
}

Copy link
Owner

@stleary stleary Jun 26, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how should I do that?

Just have 2 checks per line, so split line 2755 into 2 lines

@stleary stleary changed the title Optimization for JSONObject and JSONPointer Minor refactoring Jun 25, 2025
@stleary
Copy link
Owner

stleary commented Jun 25, 2025

What problem does this code solve?
Removes an unneeded check for null in JSONObject.wrap()

Does the code still compile with Java6?
Yes

Risks
Low

Changes to the API?
No

Will this require a new release?
No

Should the documentation be updated?
No

Does it break the unit tests?
No

Was any code refactored in this commit?
JSONPointer readByIndexToken() had a trivial change

Review status
APPROVED

Starting 3-day comment window

@sonarqubecloud
Copy link

@stleary stleary merged commit 1bdaacc into stleary:master Jun 28, 2025
8 checks passed
@stleary stleary changed the title Minor refactoring Refactoring: Remove unused code Dec 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants