jextract/jni: Add initial Foundation.Data support#557
Merged
ktoso merged 14 commits intoswiftlang:mainfrom Feb 10, 2026
Merged
Conversation
This reverts commit 84292bf.
965a925 to
e821819
Compare
e821819 to
118743f
Compare
Contributor
|
Very nice! Could we add the same mechanism for |
Collaborator
Author
|
Yep we can do that, following up |
ktoso
commented
Feb 10, 2026
| // array directly without this extra copy. For now, just map. | ||
| self = jniArray.map { Element(fromJNI: $0, in: environment) } | ||
| self = result as! Self | ||
| } else if Element.self == Int8.self { |
Collaborator
Author
There was a problem hiding this comment.
Could not nicely pull this off in a single branch... doing some small local func was even more annoying tbh -- since we need the concrete Int8.jniGetArrayRegion
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This also improves the Array.getJNIValue(in:) when the array is of bytes, addressing a long standing TODO.
I also worked on optimizing the
toByteArraysome more and now we're able to get such performance when doing the copying (by avoiding iterating and mapping data into jbytes):These work because uint8 and jbyte should be really have the same layout AFAIK so we don't need to iterate, but just rebind the memory and use the JNI funcs to initialize the java array. We could do even better by initializing into an existing array, but I didn't do that yet.
I did use the help of Claude (with lots of hand holding) to get some of the boilerplate done here, and especially make sure the FFM and JNI modes are roughly equivalent. I've read and vetted all the code and tests, and most documentation was written by myself.