Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multi-Release jar experiments #4521

Closed
wants to merge 17 commits into from
Closed

Multi-Release jar experiments #4521

wants to merge 17 commits into from

Conversation

cushon
Copy link
Collaborator

@cushon cushon commented Aug 5, 2024

No description provided.

Copy link
Contributor

@Stephan202 Stephan202 left a comment

Choose a reason for hiding this comment

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

Just a drive-by comment :)

// We could use buffer.toName(Names), but we want a string anyways and this
// avoids plumbing a Context or instances of Names through.
// Names always uses UTF-8 internally.
return new String(Arrays.copyOf(buffer.elems, buffer.length), UTF_8);
Copy link
Contributor

Choose a reason for hiding this comment

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

I recall once running a benchmark, on the basis of which I concluded that the JVM may be smart enough to conclude that in a scenario such as this one, the String constructor doesn't need to make a defensive copy of the provided array, as it'll hold the only remaining reference. Still, perhaps it's nicer to instead do:

Suggested change
return new String(Arrays.copyOf(buffer.elems, buffer.length), UTF_8);
return new String(buffer.elems, 0, buffer.length, UTF_8);

(And likewise for the Java 24 variant below.)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Thanks, good point. I had separately been considering refactoring this to pass through a VisitorState to these methods instead of Type, which would allow using buffer.toName(Names) as the comment here notes. I'll take a look at finishing that.

@cushon cushon closed this Aug 20, 2024
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