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

Value from vec #142

Merged
merged 2 commits into from Nov 10, 2022
Merged

Value from vec #142

merged 2 commits into from Nov 10, 2022

Conversation

SergioBenitez
Copy link
Contributor

@SergioBenitez SergioBenitez commented Nov 9, 2022

The first commit is an optimization, since what I was assume was originally an optimization attempt is more expensive than simply keeping the actual value around, but feel free to drop it if you'd like. The second is rather important to avoid re-allocating vectors that already contain Values when creating a Value.

Edit: Perhaps that best thing to do is to remove the generic From<T: Into<Value>> Vec<T> implementation entirely, opting instead for a From<Vec<Value>> that does what this one does. That way, the cost is immediately clear, and a more expensive .into() can't accidentally be used.

The largest variant is already at least 16 bytes, so the `Arc` only adds
an allocation without gain
@SergioBenitez SergioBenitez force-pushed the value-from-vec branch 2 times, most recently from 2fff05c to 7dacfa3 Compare November 9, 2022 23:59
Copy link
Owner

@mitsuhiko mitsuhiko left a comment

Choose a reason for hiding this comment

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

I think I would be favoring removing the From<T: Into<Value>> impl instead as you proposed.

@SergioBenitez
Copy link
Contributor Author

Alright, cleaned up a few more From impls. I actually kept the From<T: into<Value>> Vec<T> because otherwise, you can't return things like Vec<String> from a filter/function/etc. But, I added a From<Arc<Vec<Value>>> and a FromIterator which both allow cost-free creations of the Seq.

@SergioBenitez SergioBenitez force-pushed the value-from-vec branch 2 times, most recently from f15891f to bf7689e Compare November 10, 2022 04:11
Removes the now unnecessary `Value::from_arc_object`.

Adds `FromIterator` impls for:
  * 'Value' for sequences (items of `V: Into<Value>`)
  * `Value` for maps (items of `(K: Into<StaticKey>, V: Into<Value>)`)

Adds 'From' impls to `Value` from:
  * `Arc<T: Object>`
  * `u128`
  * `i128`

Finally documents the new functionality.
@mitsuhiko mitsuhiko merged commit 3241040 into mitsuhiko:main Nov 10, 2022
@mitsuhiko
Copy link
Owner

One thing I now overlooked is that the Value increased in size from 24 bytes to 32 bytes as the i128/u128 is now inlined. I will revisit this separately.

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.

None yet

2 participants