Skip to content

reduce cloning in GuaranteeRewriter#1

Merged
pepijnve merged 1 commit intopepijnve:guaranteesfrom
alamb:alamb/less_clone
Nov 19, 2025
Merged

reduce cloning in GuaranteeRewriter#1
pepijnve merged 1 commit intopepijnve:guaranteesfrom
alamb:alamb/less_clone

Conversation

@alamb
Copy link

@alamb alamb commented Nov 19, 2025


fn rewrite_between(
between: &Between,
between: Between,
Copy link
Owner

Choose a reason for hiding this comment

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

This is a style I would intuitively be inclined to avoid since it's pass-by-value both on the way in and on the way out. Does the Rust compiler guarantee that this gets optimised away?

Copy link
Author

Choose a reason for hiding this comment

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

That is a good question -- I don't know but I doubt it (the whole struct will be copied)

I think it my mind the benefit is that doing so saves the (potentially deep) cloning of the arguments

Copy link
Owner

@pepijnve pepijnve Nov 19, 2025

Choose a reason for hiding this comment

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

True, clone is a deep copy while pass by value is shallow

@pepijnve pepijnve merged commit 58868ea into pepijnve:guarantees Nov 19, 2025
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