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

load or read without creating a clone? #38

Open
WhyNotHugo opened this issue Jun 23, 2023 · 1 comment
Open

load or read without creating a clone? #38

WhyNotHugo opened this issue Jun 23, 2023 · 1 comment

Comments

@WhyNotHugo
Copy link

Whenever data is read via load or read, the data Ini instance is mutated in place, but a clone of the inner data is returned too. So I end up with two copies of the data.

Why return a clone of the data? HashMap's Clone implementation is recursive, so this ends up copying the entire structure. Am I missing something here?

Is it somehow possible to do something like Init::read, but only get one copy of the data in memory? I don't need two copies. I know that I can just drop the clone, but I don't see the point it copying data just to drop it.

@QEDK
Copy link
Owner

QEDK commented Jun 23, 2023

Whenever data is read via load or read, the data Ini instance is mutated in place, but a clone of the inner data is returned too. So I end up with two copies of the data.

Why return a clone of the data? HashMap's Clone implementation is recursive, so this ends up copying the entire structure. Am I missing something here?

Is it somehow possible to do something like Init::read, but only get one copy of the data in memory? I don't need two copies. I know that I can just drop the clone, but I don't see the point it copying data just to drop it.

This is intentional (to some extent), basically some implementations are intended to mutate in-place and others are meant to return, so it provides the best of both worlds at the cost of using more memory. If you wanted, you could simply not assign it and the compiler would know to discard the return value. In all cases, the internal impl will need to store a hashmap. In the future however, it might be beneficial to do load_inplace() / read_inplace()-esque functions.

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

No branches or pull requests

2 participants