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

feat: max_size: various small refactoring #223

Merged
merged 3 commits into from
Sep 18, 2023
Merged

feat: max_size: various small refactoring #223

merged 3 commits into from
Sep 18, 2023

Conversation

mina86
Copy link
Contributor

@mina86 mina86 commented Sep 17, 2023

  • Change is_zero_size to short-circuit internal all function when
    first element which isn’t zero sized is found.

  • Change is_zero_size to use vector of str slices as stack. There’s
    no need to allocate strings. This also makes it possible to share
    the same stack as max_serialized_size_impl.

  • Introduce Recursive error type to better encode error condition of
    is_zero_size.

  • Change max_serialized_size’s count argument to NonZeroUsize to
    encode in type system that the count is in fact never zero. In
    places where it might end up zero, the function short-circuits.

  • s/core::result::Result/Result/ since full path is no longer
    necessary after the code moved to its own module.

* Change is_zero_size to short-circuit internal all function when
  first element which isn’t zero sized is found.

* Change is_zero_size to use vector of str slices as stack.  There’s
  no need to allocate strings.  This also makes it possible to share
  the same stack as max_serialized_size_impl.

* Introduce Recursive error type to better encode error condition of
  is_zero_size.

* Change max_serialized_size’s count argument to NonZeroUsize to
  encode in type system that the count is in fact never zero.  In
  places where it might end up zero, the function short-circuits.
@@ -115,15 +115,25 @@ fn max_serialized_size_impl<'a>(
Ok(Definition::Array { length, elements }) => {
// Aggregate `count` and `length` to a single number. If this
// overflows, check if array’s element is zero-sized.
let count = usize::try_from(*length)
let count_lengths = usize::try_from(*length)
Copy link
Collaborator

Choose a reason for hiding this comment

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

using the same count name everywhere was confusing to me

@dj8yfo dj8yfo merged commit 56405eb into near:master Sep 18, 2023
7 checks passed
@frol frol mentioned this pull request Sep 18, 2023
@mina86 mina86 deleted the b branch September 19, 2023 08:06
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