-
-
Notifications
You must be signed in to change notification settings - Fork 644
Refactored memset and memcpy calls to D slices in multiple files #21147
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?
Refactored memset and memcpy calls to D slices in multiple files #21147
Conversation
Replace C-style memory functions with D slice operations in:\n- compiler/src/dmd/common/outbuffer.d\n- compiler/src/dmd/dcast.d\n- compiler/src/dmd/root/array.d\n- compiler/src/dmd/root/bitarray.d\n\nThis makes the code more idiomatic to D and safer.
Thanks for your pull request and interest in making D better, @AbhayPratap05! We are looking forward to reviewing it, and you should be hearing from a maintainer soon.
Please see CONTRIBUTING.md for more information. If you have addressed all reviews or aren't sure how to proceed, don't hesitate to ping us with a simple comment. Bugzilla referencesYour PR doesn't reference any Bugzilla issue. If your PR contains non-trivial changes, please reference a Bugzilla issue or create a manual changelog. Testing this PR locallyIf you don't have a local development environment setup, you can use Digger to test this PR: dub run digger -- build "master + dmd#21147" |
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.
Hi, thanks for the PR.
What is the net benefit of this change?
From a code-gen stance, both current and proposed changes are identical.
The current code is arguably more readable too. Drop the casts, and it would start to look like an improvement.
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 for the changes to dcast.d.
OutBuffer and Array are very common optimized abstractions based on low-level building blocks. As a consequence, many of the translated slice expressions are more complex than the original memset/memcpy. On top of that, since slices have bounds checking, there is a performance regression risk (since we don't have the tester from the GSoC project yet), so please refrain from those refactorings for now.
…cast in dmd/dcast.d
This PR reverts the previous slice-based casts and instead:
The changes follows mentor feedback to avoid performance regressions in OutBuffer and Array. |
Co-authored-by: Dennis <[email protected]>
Co-authored-by: Dennis <[email protected]>
This PR replaces C-style memcpy and memset calls with D slice operations in several files:
Changes made:
memset
calls with D slice assignments:(cast(ubyte*)ptr)[0 .. size] = 0
memcpy
calls with D slice copying:(cast(ubyte*)dest)[0 .. size] = (cast(const(ubyte)*)src)[0 .. size]
Testing: