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

Remove restrict (for the most part) #2145

Merged
merged 1 commit into from
Dec 10, 2024

Conversation

eboasson
Copy link
Contributor

A lot of "restricts" were sprinkled throughout the code, for the most part completely unnecessary because it didn't even involve performance-sensitive code. C++ does not have the "restrict" keyword, and the work-around for that was #defining it away, which breaks C++ code using "restrict" as an identifier. In short, a bit of a mess.

This removes the vast majority, including in particular all in the API and thus eliminating any need for a C++-specific workaround. The only cases that remain are in the (de)serializers because:

  • they are performance-sensitive
  • they read/write through "char *" pointers that are allowed to alias anything
  • a cursory inspection of the output of gcc suggests it does affects the code

This PR sits on top of #2124, mainly because of laziness. The two PRs are not entirely independent (because of the serializer), but this PR can easily be changed to apply to master if this one gets the green light but the other one does not (yet?). The changes exclusive to this PR are all in a single commit, so it is pretty easy to review the restrict part without having to wade through unrelated changes.

Fixes #2140

Copy link
Contributor

@dpotman dpotman left a comment

Choose a reason for hiding this comment

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

The changes look fine to me! I agree with removing most of the restricts, as in many of these code blocks it isn't relevant because there are no loops doing memory access or not used in a path where performance is critical.

Removing restrict for const parameters and only keep it for the non-const (e.g. in plist) seems to be fine, as it follows this example. But on the other hand, e.g. the memcpy functions in C do use it on both parameters, although that seems to be just for clarification and not strictly necessary.

Not completely sure about some generic ddsrt functions like ddsrt_strlcpy and ddsrt_strlcat, that pass the parameters directly into memcpy. So src and dst need to be restrict, and wouldn't it be good to show that in the declaration of these functions?

In cdrstream, what the reason for removing restrict on the write functions? Some of them use memcpy, so I'd expect the os parameter (or the buffer in os) to be restrict?

A lot of "restricts" were sprinkled throughout the code, for the most part completely
unnecessary because it didn't even involve performance-sensitive code. C++ does not have
the "restrict" keyword, and the work-around for that was #defining it away, which breaks
C++ code using "restrict" as an identifier. In short, a bit of a mess.

This removes the vast majority, including in particular all in the API and thus
eliminating any need for a C++-specific workaround. The only cases that remain are in
the (de)serializers because:

* they are performance-sensitive

* they read/write through "char *" pointers that are allowed to alias anything

* a cursory inspection of the output of gcc suggests it does affects the code

Signed-off-by: Erik Boasson <[email protected]>
@eboasson
Copy link
Contributor Author

eboasson commented Dec 9, 2024

I rebased the PR on current master, which needed a few touch-ups after the fixes in the wstring-support. Those are really trivial: dds_stream_reuse_string_bound and wstring_from_utf16 gained a restrict (I overlooked it before).

@eboasson eboasson merged commit 82f1365 into eclipse-cyclonedds:master Dec 10, 2024
17 of 21 checks passed
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.

Do not #define restrict
2 participants