Skip to content

Conversation

@hyf0
Copy link
Contributor

@hyf0 hyf0 commented Jan 14, 2023

Description:

This PR supports allowing Atom to store &'static str in it.

BREAKING CHANGE:

Related issue (if exists):
#4946


impl PartialEq for Atom {
fn eq(&self, other: &Self) -> bool {
// Fast path
Copy link
Contributor Author

@hyf0 hyf0 Jan 14, 2023

Choose a reason for hiding this comment

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

@kdy1 After supporting Atom::static, I'm not sure the fast path will work as before. To keep the logic same as before, we need to call match twice. I'm going to remove the code, in case I miss something, what are your opinions?

Copy link
Contributor Author

@hyf0 hyf0 Jan 14, 2023

Choose a reason for hiding this comment

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

Also, should Atom promise assert!(Atom::Arc("foo") == Atom::Static("foo"))?

Copy link
Member

Choose a reason for hiding this comment

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

I think it's fine, but assert!(Atom::Arc("foo") == Atom::Static("foo")) should work

}

// fn _assert_size() {
// let _static_assert_size_eq = std::mem::transmute::<Atom, usize>;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@kdy1 The transmute seems not to work, after making Atom(ThinArc<HeaderWithLength<()>, u8>) to Atom(Inner).

Is this expected?
image

Copy link
Member

Choose a reason for hiding this comment

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

Yes, but it will degrade performance greatly.

I didn't implement static support because it's hard

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I get the gist. We need something like ThinStaticStr. It's indeed hard after looking into thin_tr. I will try it, but it will take a while.

If anyone wants to try this, feel free to do it.

@hyf0 hyf0 closed this Feb 20, 2023
@swc-project swc-project locked as resolved and limited conversation to collaborators Mar 22, 2023
@kdy1 kdy1 added this to the Unknown milestone Jul 21, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants