-
Notifications
You must be signed in to change notification settings - Fork 3.4k
dart: Return dart:typed_data equivalent where possible #8289
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
base: master
Are you sure you want to change the base?
Conversation
|
I'm not opposed to that, but I'd like to see some insight from one of the Dart maintainers to see if this aligns with their view for the Dart side. Ideally, we could expand the same to |
Ready for review. I tested using @tompark's example code, with the latest version of flatbuffers on pub.dev as well as this fork, and this fork prints the expected |
I squashed the changes and removed a change related to my other PR to prevent conflicts between the two. @vaind Hi Ivan, is there any way you might be able to spare some bandwidth in the relatively near future to help review and potentially land both of my open PRs? Cheers. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks a lot. It looks pretty good to me, although there need to be some changes to make the code correct on Big endian machines (I know these are basically non-existent, but since Dart supports them, we should too).
I think I'd rather add a separate path or built-in for big-endian, otherwise the newly added conditions to the tests will cause the tests to fail on big-endian, as the old classes do not return Uint8List, Int8List, Uint16List, etc on the lazy path. I think the only supported test environment (theoretically) would be ARM on Linux running in big-endian mode? I'll try and set up a qemu environment to test. |
I think it's OK to have different actual return type on big endian, the only contract is that it is compatible with List, everything else is "just" an optimization. It's OK for tests to assert the return value is the expected type based on endianness though |
Sounds good to me. Sorry for the delay. I'll get this updated this week, hopefully on the earlier half as opposed to the later half. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM.
Are you going to do the other lists (int32, ...) too or is this PR finished?
I'll extend this to other types! I'll expand the tests as well. |
@vaind I couldn't find out what is causing Float64List to fail, so I am going to revert the changes to the Float types and mark them with a todo to return their dart:typed_data equivalent so the PR can be restored to a working state and will be ready for review. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM but I cannot merge as I'm not a maintainer.
* Remove _FbUint8List, _FbInt8List and _FbUint16List to return typed_data types * Add test for Int8List * Test Int8List, Uint8List and Uint16List for type equivalence * Remove unnecessary cast in _writeUTFString to silence linting warning
* This involved fixing writeListFloat32 and writeListFloat64 by preventing misalignment from occurring
I had some time to sit down and review this again, and saw that the old code was causing potential misalignment in writeListFloat32 and writeListFloat64. Before we were treating all of the data as part of the count in _prepare, which technically does calculate the correct number of bytes but can cause misalignment, now we treat the length field correctly as a uint32 rather than as part of the float data, and specify the data as additionalBytes. I also let GH rebase this. This is the final version of the PR, pending any code change requests from review. Hoping to see this actually go somewhere now, |
@aardappel Could you perhaps give this a look in spare time? |
@NotTsunami sorry, I have zero knowledge of Dart. I guess I am fine to merge if @vaind thinks it is ok. @dbaileychess who probably know Dart better than I do. Also, there is a failing test. |
Thanks. Should be fixed. Pending review on the latest version of the PR now, then. |
Please merge it soon. |
Stems from discussion in #8183. This should allow users to be able to access a Uint8List directly without copying over from a list, thus actually offering zero-copy access (for this class, at least) in both the lazy path and the non-lazy path. This is pretty important for signal processing and image processing where we want to avoid any unnecessary list copies.