Skip to content

Add convenience impls for common types#137

Merged
mmagician merged 6 commits intomasterfrom
add-convenience-impls
Jan 27, 2024
Merged

Add convenience impls for common types#137
mmagician merged 6 commits intomasterfrom
add-convenience-impls

Conversation

@Pratyush
Copy link
Member

Description

closes: #XXXX


Before we can merge this PR, please make sure that all the following items have been
checked off. If any of the checklist items are not applicable, please leave them but
write a little note why.

  • Targeted PR against correct branch (master)
  • Linked to Github issue with discussion and accepted design OR have an explanation in the PR that describes this work.
  • Wrote unit tests
  • Updated relevant documentation in the code
  • Added a relevant changelog entry to the Pending section in CHANGELOG.md
  • Re-reviewed Files changed in the Github PR explorer

@Pratyush Pratyush requested a review from a team as a code owner January 18, 2024 03:26
@Pratyush Pratyush requested review from mmagician, weikengchen and z-tech and removed request for a team January 18, 2024 03:26
@Pratyush Pratyush force-pushed the add-convenience-impls branch from 4d0bf30 to e7a75be Compare January 26, 2024 02:20
@Pratyush Pratyush requested review from mmagician and removed request for mmagician January 26, 2024 02:49
Copy link
Member

@mmagician mmagician left a comment

Choose a reason for hiding this comment

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

One question on the logic, otherwise LGTM

let elem = elem.to_bytes_le()?;
bytes.extend_from_slice(&elem);
// Make sure that there's enough capacity to avoid reallocations.
bytes.reserve(elem.len() * (self.len() - 1));
Copy link
Member

Choose a reason for hiding this comment

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

Do we do this at each iteration of the loop in case the elements have different len?

Copy link
Member Author

Choose a reason for hiding this comment

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

This actually wasn't the smartest logic, but it kind of works out: if the elem.len() is less than or equal to that for previous elems, then don't change the capacity, resulting in a no-op. If elem.len() is larger than that for previous elems, it will reserve more space.

@mmagician mmagician merged commit 4020fbc into master Jan 27, 2024
@mmagician mmagician deleted the add-convenience-impls branch January 27, 2024 08:58
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.

2 participants