Skip to content

macros: Fix indentation of cssparser_internal_to_lowercase. #334

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

Merged
merged 1 commit into from
Apr 27, 2023
Merged
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
25 changes: 12 additions & 13 deletions src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,22 +152,21 @@ pub fn _cssparser_internal_to_lowercase<'a>(
input: &'a str,
first_uppercase: usize,
) -> &'a str {

// This cast doesn't change the pointer's validity
// since `u8` has the same layout as `MaybeUninit<u8>`:
let input_bytes = unsafe { &*(input.as_bytes() as *const [u8] as *const [MaybeUninit<u8>]) };
// This cast doesn't change the pointer's validity
// since `u8` has the same layout as `MaybeUninit<u8>`:
let input_bytes =
unsafe { &*(input.as_bytes() as *const [u8] as *const [MaybeUninit<u8>]) };

buffer.copy_from_slice(&*input_bytes);
buffer.copy_from_slice(&*input_bytes);

// Same as above re layout, plus these bytes have been initialized:
let buffer = unsafe { &mut *(buffer as *mut [MaybeUninit<u8>] as *mut [u8]) };
// Same as above re layout, plus these bytes have been initialized:
let buffer = unsafe { &mut *(buffer as *mut [MaybeUninit<u8>] as *mut [u8]) };

buffer[first_uppercase..].make_ascii_lowercase();
// `buffer` was initialized to a copy of `input`
// (which is `&str` so well-formed UTF-8)
// then ASCII-lowercased (which preserves UTF-8 well-formedness):
unsafe { ::std::str::from_utf8_unchecked(buffer) }

buffer[first_uppercase..].make_ascii_lowercase();
// `buffer` was initialized to a copy of `input`
// (which is `&str` so well-formed UTF-8)
// then ASCII-lowercased (which preserves UTF-8 well-formedness):
unsafe { ::std::str::from_utf8_unchecked(buffer) }
}

Some(
Expand Down