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

Pass USB_OTG_CfgTypeDef by reference. #16

Conversation

dlech
Copy link

@dlech dlech commented Sep 27, 2021

This updates all HAL libraries to pass USB_OTG_CfgTypeDef by reference. USB_OTG_CfgTypeDef is a large struct that is being passed by value which uses extra stack and bigger code due to the extra copy of the struct.

@dpgeorge
Copy link
Member

Thanks, this looks like a good optimisation. It might make it harder to update to newer HAL versions, but I guess we can deal with that when needed.

Would it be better to pass it in as a const USB_OTG_CfgTypeDef*? Then it's guaranteed the caller won't change the struct, which retains semantics with pass-by-value.

@dlech
Copy link
Author

dlech commented Nov 26, 2021

Would it be better to pass it in as a const USB_OTG_CfgTypeDef*? Then it's guaranteed the caller won't change the struct, which retains semantics with pass-by-value.

Yes, that sounds like a good idea.

dlech added 7 commits December 8, 2021 12:59
USB_OTG_CfgTypeDef is a large struct, so passing by reference should
be more efficient in terms of stack usage and code size.

Signed-off-by: David Lechner <[email protected]>
USB_OTG_CfgTypeDef is a large struct, so passing by reference should
be more efficient in terms of stack usage and code size.

Signed-off-by: David Lechner <[email protected]>
USB_OTG_CfgTypeDef is a large struct, so passing by reference should
be more efficient in terms of stack usage and code size.

Signed-off-by: David Lechner <[email protected]>
USB_OTG_CfgTypeDef is a large struct, so passing by reference should
be more efficient in terms of stack usage and code size.

Signed-off-by: David Lechner <[email protected]>
USB_OTG_CfgTypeDef is a large struct, so passing by reference should
be more efficient in terms of stack usage and code size.

Signed-off-by: David Lechner <[email protected]>
USB_OTG_CfgTypeDef is a large struct, so passing by reference should
be more efficient in terms of stack usage and code size.

Signed-off-by: David Lechner <[email protected]>
USB_OTG_CfgTypeDef is a large struct, so passing by reference should
be more efficient in terms of stack usage and code size.

Signed-off-by: David Lechner <[email protected]>
@dlech
Copy link
Author

dlech commented Dec 8, 2021

I have updated with the suggested change.

@dpgeorge
Copy link
Member

Thanks for updating. Merged in 5039e29 through f0ff2b2

@dpgeorge dpgeorge closed this Dec 13, 2021
@dlech dlech deleted the usb-cfg-type-def branch December 13, 2021 14:59
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.

2 participants