mirror of
https://github.com/servo/servo.git
synced 2025-08-05 21:50:18 +01:00
clippy: Fix unnecessary_cast
warnings in components/script
(#31823)
* clippy: Fix unnecessary cast warnings * clippy: Replace redundant field names with their shorthand alternatives * clippy: Delete struct pattern dereferencings
This commit is contained in:
parent
3e9b808938
commit
bae77671f8
21 changed files with 32 additions and 45 deletions
|
@ -422,14 +422,13 @@ where
|
|||
}
|
||||
|
||||
unsafe {
|
||||
let mapping_slice_ptr =
|
||||
mapping.lock().unwrap().borrow_mut()[offset as usize..m_end as usize].as_mut_ptr();
|
||||
let mapping_slice_ptr = mapping.lock().unwrap().borrow_mut()[offset..m_end].as_mut_ptr();
|
||||
|
||||
// rooted! is needed to ensure memory safety and prevent potential garbage collection issues.
|
||||
// https://github.com/mozilla-spidermonkey/spidermonkey-embedding-examples/blob/esr78/docs/GC%20Rooting%20Guide.md#performance-tweaking
|
||||
rooted!(in(*cx) let array_buffer = NewExternalArrayBuffer(
|
||||
*cx,
|
||||
range_size as usize,
|
||||
range_size,
|
||||
mapping_slice_ptr as _,
|
||||
Some(free_func),
|
||||
Arc::into_raw(mapping) as _,
|
||||
|
|
|
@ -228,8 +228,8 @@ pub unsafe fn jsstring_to_str(cx: *mut JSContext, s: *mut JSString) -> DOMString
|
|||
let mut length = 0;
|
||||
let chars = JS_GetTwoByteStringCharsAndLength(cx, ptr::null(), s, &mut length);
|
||||
assert!(!chars.is_null());
|
||||
let potentially_ill_formed_utf16 = slice::from_raw_parts(chars, length as usize);
|
||||
let mut s = String::with_capacity(length as usize);
|
||||
let potentially_ill_formed_utf16 = slice::from_raw_parts(chars, length);
|
||||
let mut s = String::with_capacity(length);
|
||||
for item in char::decode_utf16(potentially_ill_formed_utf16.iter().cloned()) {
|
||||
match item {
|
||||
Ok(c) => s.push(c),
|
||||
|
@ -282,7 +282,7 @@ impl FromJSValConvertible for USVString {
|
|||
let mut length = 0;
|
||||
let chars = JS_GetTwoByteStringCharsAndLength(cx, ptr::null(), jsstr, &mut length);
|
||||
assert!(!chars.is_null());
|
||||
let char_vec = slice::from_raw_parts(chars as *const u16, length as usize);
|
||||
let char_vec = slice::from_raw_parts(chars as *const u16, length);
|
||||
Ok(ConversionResult::Success(USVString(
|
||||
String::from_utf16_lossy(char_vec),
|
||||
)))
|
||||
|
@ -324,7 +324,7 @@ impl FromJSValConvertible for ByteString {
|
|||
let chars = JS_GetLatin1StringCharsAndLength(cx, ptr::null(), string, &mut length);
|
||||
assert!(!chars.is_null());
|
||||
|
||||
let char_slice = slice::from_raw_parts(chars as *mut u8, length as usize);
|
||||
let char_slice = slice::from_raw_parts(chars as *mut u8, length);
|
||||
return Ok(ConversionResult::Success(ByteString::new(
|
||||
char_slice.to_vec(),
|
||||
)));
|
||||
|
@ -332,7 +332,7 @@ impl FromJSValConvertible for ByteString {
|
|||
|
||||
let mut length = 0;
|
||||
let chars = JS_GetTwoByteStringCharsAndLength(cx, ptr::null(), string, &mut length);
|
||||
let char_vec = slice::from_raw_parts(chars, length as usize);
|
||||
let char_vec = slice::from_raw_parts(chars, length);
|
||||
|
||||
if char_vec.iter().any(|&c| c > 0xFF) {
|
||||
throw_type_error(cx, "Invalid ByteString");
|
||||
|
|
|
@ -776,7 +776,7 @@ fn max_day_in_month(year_num: i32, month_num: u32) -> Option<u32> {
|
|||
|
||||
/// <https://html.spec.whatwg.org/multipage/#week-number-of-the-last-day>
|
||||
fn max_week_in_year(year: i32) -> u32 {
|
||||
Utc.with_ymd_and_hms(year as i32, 1, 1, 0, 0, 0)
|
||||
Utc.with_ymd_and_hms(year, 1, 1, 0, 0, 0)
|
||||
.earliest()
|
||||
.map(|date_time| match date_time.weekday() {
|
||||
Weekday::Thu => 53,
|
||||
|
|
|
@ -451,7 +451,7 @@ pub unsafe extern "C" fn resolve_global(
|
|||
let mut length = 0;
|
||||
let ptr = JS_GetLatin1StringCharsAndLength(cx, ptr::null(), string, &mut length);
|
||||
assert!(!ptr.is_null());
|
||||
let bytes = slice::from_raw_parts(ptr, length as usize);
|
||||
let bytes = slice::from_raw_parts(ptr, length);
|
||||
|
||||
if let Some(init_fun) = InterfaceObjectMap::MAP.get(bytes) {
|
||||
init_fun(SafeJSContext::from_ptr(cx), Handle::from_raw(obj));
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue