Skip to content

Remove redundant recordPromotedName calls - #3117

Merged
eamonnmcmanus merged 2 commits into
google:mainfrom
Marcono1234:marcono1234/redundant-promoted-name
Sep 12, 2026
Merged

Remove redundant recordPromotedName calls#3117
eamonnmcmanus merged 2 commits into
google:mainfrom
Marcono1234:marcono1234/redundant-promoted-name

Conversation

@Marcono1234

Copy link
Copy Markdown
Contributor

Purpose

Follow-up for #3098

Description

These recordPromotedName calls are guarded by a case PEEKED_LONG, but it seems PEEKED_LONG is only used if an actual number occurred in the JSON document. Whereas when promoting a name to a value, it will always be a JSON string value.

These redundant calls were also the "expensive" ones, converting a long to a String.

reader.beginObject();
JsonReaderInternalAccess.INSTANCE.promoteNameToValue(reader);
reader.skipValue();
String expectedPath = factory == Factory.STRING_READER ? "$.<skipped>" : "$.name";

@Marcono1234 Marcono1234 Sep 11, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This also highlights a difference between JsonReader and JsonTreeReader. But I guess this is fine: JsonReader uses the dummy name <skipped> for efficiency to avoid having to obtain the name as String. Whereas JsonTreeReader has the name available as String anyway.

For JsonTreeReader the behavior for skipValue() now differs between a regular name and a promoted one, but that is probably still fine.
Trying to fix that would make the JsonTreeReader implementation more complex because it would now need a dedicated field as well to remember whether a name had been promoted.

@Marcono1234
Marcono1234 marked this pull request as ready for review September 11, 2026 11:50
These calls are guarded by a `case PEEKED_LONG`, but it seems
`PEEKED_LONG` is only used if an actual number occurred in the JSON
document. Whereas when promoting a name to a value, it will always be a
JSON string value.

These redundant calls were also the "expensive" ones, converting a long
to a String.
@Marcono1234
Marcono1234 force-pushed the marcono1234/redundant-promoted-name branch from ee090fc to 1c328fc Compare September 11, 2026 11:56

@eamonnmcmanus eamonnmcmanus left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks for noticing this!

@eamonnmcmanus
eamonnmcmanus merged commit ed99017 into google:main Sep 12, 2026
21 checks passed
@Marcono1234
Marcono1234 deleted the marcono1234/redundant-promoted-name branch September 14, 2026 10:48
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.

2 participants