Skip to content

Stop leaking strings in Python downloads#15418

Merged
konstin merged 1 commit intomainfrom
konsti/stop-leaking-strings
Aug 21, 2025
Merged

Stop leaking strings in Python downloads#15418
konstin merged 1 commit intomainfrom
konsti/stop-leaking-strings

Conversation

@konstin
Copy link
Member

@konstin konstin commented Aug 21, 2025

We should not unnecessarily leak memory. Instead, we follow the general patterns and use Cow for strings that can be from either a static or a dynamic source.

We should not unnecessarily leak memory.
@konstin konstin requested a review from zanieb August 21, 2025 14:23
@konstin konstin added the internal A refactor or improvement that is not user-facing label Aug 21, 2025
Comment on lines +330 to +331
url: Some(download.url().clone()),
sha256: download.sha256().cloned(),
Copy link
Member Author

Choose a reason for hiding this comment

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

This only allocates if we have a Cow::Owned


pub fn url(&self) -> &'static str {
self.url
pub fn url(&self) -> &Cow<'static, str> {
Copy link
Member Author

Choose a reason for hiding this comment

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

Returning the full Cow here allows the cheap clones below.

@zanieb
Copy link
Member

zanieb commented Aug 21, 2025

cc @Gankra as the reviewer on #10939

@konstin konstin merged commit 25bedea into main Aug 21, 2025
96 checks passed
@konstin konstin deleted the konsti/stop-leaking-strings branch August 21, 2025 15:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

internal A refactor or improvement that is not user-facing

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants