X Tutup
Skip to content

Use const ref parameters in the Web modules#110977

Merged
Repiteo merged 1 commit intogodotengine:masterfrom
aaronfranke:const-ref-param-webrtc
Sep 30, 2025
Merged

Use const ref parameters in the Web modules#110977
Repiteo merged 1 commit intogodotengine:masterfrom
aaronfranke:const-ref-param-webrtc

Conversation

@aaronfranke
Copy link
Member

@aaronfranke aaronfranke commented Sep 27, 2025

This PR changes parameters in the WebRTC, WebSocket, and WebXR modules to const refs: const Type &. This change prevents making unnecessary copies of parameters when calling functions, including when the bindings call the functions.

Motivation: I tried changing the copy constructors of container types like Array to explicit, but this creates a problem for non-const-ref parameters of container types in the bindings. Right now, the bindings are implicitly making copies of this data, and the bindings do not compile anymore if this is changed to explicit. See the discussions in PR #107377 and PR #110912 for more information.

Only doing this for container types would be sufficient for that purpose, but that would be a massive change throughout the entire codebase. I think it would be better for reviewability if I open multiple PRs targeting specific parts of the codebase, so for example, this PR can be reviewed by the maintainers of the web platform. And, while I'm at it, I also made this change for types such as String and Ref<> to fix up those too.

This PR also contains a small number of other changes to parameters, such as using snake_case names consistently.

Copy link
Contributor

@dsnopek dsnopek left a comment

Choose a reason for hiding this comment

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

Thanks!

I'm in support of the changes to the function arguments: those make this code consistent with the style used throughout the rest of Godot's code base. However, as I noted on the other PR, perhaps the other changes should be left out for now?

(I'm a little embarrassed that I didn't do const String & in the WebXR code :-/)

@aaronfranke aaronfranke force-pushed the const-ref-param-webrtc branch from e24bcc3 to ac2e016 Compare September 28, 2025 15:14
@dsnopek dsnopek requested a review from adamscott September 28, 2025 17:10
Copy link
Contributor

@dsnopek dsnopek left a comment

Choose a reason for hiding this comment

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

This looks good to me!

@Repiteo Repiteo merged commit 0e7bb92 into godotengine:master Sep 30, 2025
20 checks passed
@Repiteo
Copy link
Contributor

Repiteo commented Sep 30, 2025

Thanks!

@aaronfranke aaronfranke deleted the const-ref-param-webrtc branch September 30, 2025 16:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

X Tutup