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

Some actual proper design for internals #15

Open
maciejhirsz opened this issue Mar 18, 2020 · 4 comments
Open

Some actual proper design for internals #15

maciejhirsz opened this issue Mar 18, 2020 · 4 comments

Comments

@maciejhirsz
Copy link
Owner

maciejhirsz commented Mar 18, 2020

Messing around between the fat pointer and thin pointer is quite a lot of work, and there is quite some deep coupling between generic::Cow, the Beef trait and the Capacity. Capacity is also a poor name for what the trait is doing now.

A reasonable logical split would be:

  • generic::Cow implements the API surface, methods like borrow, owned and into_owned, as well as all the traits one expects.
  • Beef converts borrowed and owned values into parts (pointer, len, cap) and back.
  • Rename Capacity to something like Container, have it store (pointer, len, cap) from Beef internally so that the particulars of how capacity is handled doesn't leak out to other abstractions.
@pickfire
Copy link
Contributor

pickfire commented Mar 27, 2020

Is there a reason why it needs to be (pointer, len, cap) and not (pointer, cap, len) for Lean? Is it related to performance?

@maciejhirsz
Copy link
Owner Author

No, the Container here would be able to arrange stuff in whatever order it wants. Currently lean version is (ptr, len) with capacity put into higher 32 bits of len, so that obtaining a reference can be done by just masking those bits.

@pickfire
Copy link
Contributor

Yeah, regarding the current design, I was asking why capacity were put into the higher 32 bits of length rather than length were put into the higher 32 bits of capacity? Isn't capacity being used more since it also stores the tag when capacity is 0?

@maciejhirsz
Copy link
Owner Author

maciejhirsz commented Mar 28, 2020

No, capacity is only used:

  • When you call into_owned.
  • When the Cow is cloned.
  • When the Cow is dropped.

Most of what you want to do with a Cow is to read from it, which means creating a &ref (via Deref or Borrow). With the pointer and length in the same position for owned and borrowed values, getting a &ref is, unlike std implementation, branch free.

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