-
Notifications
You must be signed in to change notification settings - Fork 0
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
CloneIn
unnecessarily copies strings when cloning within same allocator
#96
Comments
I think perhaps what we need is 2 different traits:
|
One further thought: Alternative for cloning within same allocatorThe root cause of why we need to call If we encoded a reference to allocator within
Therefore, regardless of what may become possible in future, I feel we'd be better off introducing the clone-within-same-allocator version of |
…ne_in` on `LabelIdentifier` (#7172) Follow-on after stack up to #7148. Small optimization. `LabelIdentifier` is `Clone` so we can use `Clone::clone` to clone it, instead of `CloneIn::clone_in`. The difference is that `clone_in` makes a 2nd copy of the `Atom`'s string in the arena, whereas `clone` creates a new `Atom` referencing the same string. This is an unfortunate shortcoming of `CloneIn` (oxc-project/backlog#96), but the more we can avoid `CloneIn`, the better.
https://github.com/oxc-project/oxc/blob/2476dceee0a656a00d5138e0aeb34b5c062883d8/crates/oxc_span/src/atom.rs#L62-L68
https://github.com/oxc-project/oxc/blob/2476dceee0a656a00d5138e0aeb34b5c062883d8/crates/oxc_span/src/atom.rs#L76-L80
So
Atom::clone_in
copies the underlying string data and re-allocates it in new allocator.This is the correct behavior when cloning from one allocator into another allocator - string data does need to be copied into the new allocator.
But when cloning within same allocator, this string copying is unnecessary. Could just do
Atom::clone
, which creates another reference to original underlying string data, with no data copy.Not sure how to avoid this copying. Do we need a 2nd cloning trait for within-same-allocator cloning? And how would we enforce that the
allocator
provided toclone_in
is the same allocator as the original? (or maybe we don't need to exactly -'old_alloc: 'new_alloc
would suffice to ensure that the string data in old allocator lives longer than the newAtom
).The text was updated successfully, but these errors were encountered: