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

Inline single-use unsafe function + simplify related unsafe + fix typo #189

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 3 additions & 10 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1018,21 +1018,14 @@ fn parse_headers_iter<'a>(
) -> Result<usize> {
parse_headers_iter_uninit(
/* SAFETY: see `parse_headers_iter_uninit` guarantees */
unsafe { deinit_slice_mut(headers) },
unsafe { &mut *(headers as *mut &mut _ as *mut &mut [MaybeUninit<_>]) },
bytes,
config,
)
}

unsafe fn deinit_slice_mut<'a, 'b, T>(s: &'a mut &'b mut [T]) -> &'a mut &'b mut [MaybeUninit<T>] {
let s: *mut &mut [T] = s;
let s = s as *mut &mut [MaybeUninit<T>];
&mut *s
}
unsafe fn assume_init_slice<T>(s: &mut [MaybeUninit<T>]) -> &mut [T] {
let s: *mut [MaybeUninit<T>] = s;
let s = s as *mut [T];
&mut *s
&mut *(s as *mut _ as *mut [_])
}

#[derive(Clone, Debug, Default)]
Expand All @@ -1043,7 +1036,7 @@ struct HeaderParserConfig {
ignore_invalid_headers: bool,
}

/* Function which parsers headers into uninitialized buffer.
/* Function which parses headers into uninitialized buffer.
*
* Guarantees that it doesn't write garbage, so casting
* &mut &mut [Header] -> &mut &mut [MaybeUninit<Header>]
Expand Down
Loading