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

Only create one UnsafeAllocator instance #2196

Merged
merged 2 commits into from
Sep 29, 2022

Conversation

kb-1000
Copy link
Contributor

@kb-1000 kb-1000 commented Sep 19, 2022

This reduces unnecessary allocations, and may potentially even help the JIT (at least for regular JVMs, unsure about Android) optimize the code a little bit more.

@eamonnmcmanus
Copy link
Member

Thanks, I agree this seems like a good idea. One small thing: this line

    final String exceptionMessage = UnsafeAllocator.checkInstantiable(rawType);

causes the static initializer for UnsafeAllocator to run and that will now attempt to create an UnsafeAllocator. Could you wrap the code-block containing the above line in if (useJdkUnsafe)?

@Marcono1234
Copy link
Collaborator

Could you wrap the code-block containing the above line in if (useJdkUnsafe)?

Maybe it would be better to move the method checkInstantiable to ConstructorConstructor instead? The point of this check is to also provide a correct exception message if useJdkUnsafe == false, see comment above the checkInstantiable call.

@eamonnmcmanus eamonnmcmanus merged commit 9c9cafc into google:master Sep 29, 2022
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