mirror of
https://github.com/servo/servo.git
synced 2025-06-06 16:45:39 +00: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
|
@ -607,7 +607,7 @@ impl CanvasState {
|
|||
) -> (Rect<f64>, Rect<f64>) {
|
||||
let image_rect = Rect::new(
|
||||
Point2D::new(0f64, 0f64),
|
||||
Size2D::new(image_size.width as f64, image_size.height as f64),
|
||||
Size2D::new(image_size.width, image_size.height),
|
||||
);
|
||||
|
||||
// The source rectangle is the rectangle whose corners are the four points (sx, sy),
|
||||
|
|
|
@ -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));
|
||||
|
|
|
@ -59,7 +59,7 @@ impl CanvasGradientMethods for CanvasGradient {
|
|||
};
|
||||
|
||||
self.stops.borrow_mut().push(CanvasGradientStop {
|
||||
offset: (*offset) as f64,
|
||||
offset: (*offset),
|
||||
color,
|
||||
});
|
||||
Ok(())
|
||||
|
|
|
@ -2001,7 +2001,7 @@ impl GlobalScope {
|
|||
|
||||
let stream = ReadableStream::new_with_external_underlying_source(
|
||||
self,
|
||||
ExternalUnderlyingSource::Blob(size as usize),
|
||||
ExternalUnderlyingSource::Blob(size),
|
||||
);
|
||||
|
||||
let recv = self.send_msg(file_id);
|
||||
|
@ -3171,7 +3171,7 @@ impl GlobalScope {
|
|||
}
|
||||
}
|
||||
for i in (0..gamepad_list.Length()).rev() {
|
||||
if gamepad_list.Item(i as u32).is_none() {
|
||||
if gamepad_list.Item(i).is_none() {
|
||||
gamepad_list.remove_gamepad(i as usize);
|
||||
} else {
|
||||
break;
|
||||
|
@ -3211,7 +3211,7 @@ impl GlobalScope {
|
|||
if !window.Navigator().has_gamepad_gesture() && contains_user_gesture(update_type) {
|
||||
window.Navigator().set_has_gamepad_gesture(true);
|
||||
for i in 0..gamepad_list.Length() {
|
||||
if let Some(gamepad) = gamepad_list.Item(i as u32) {
|
||||
if let Some(gamepad) = gamepad_list.Item(i) {
|
||||
gamepad.set_exposed(true);
|
||||
gamepad.update_timestamp(*current_time);
|
||||
let new_gamepad = Trusted::new(&*gamepad);
|
||||
|
|
|
@ -222,8 +222,8 @@ impl Area {
|
|||
.iter()
|
||||
.enumerate()
|
||||
.map(|(index, point)| match index % 2 {
|
||||
0 => point + p.x as f32,
|
||||
_ => point + p.y as f32,
|
||||
0 => point + p.x,
|
||||
_ => point + p.y,
|
||||
});
|
||||
Area::Polygon {
|
||||
points: iter.collect::<Vec<_>>(),
|
||||
|
|
|
@ -393,7 +393,7 @@ impl HTMLFormElementMethods for HTMLFormElement {
|
|||
|
||||
// https://html.spec.whatwg.org/multipage/#dom-form-length
|
||||
fn Length(&self) -> u32 {
|
||||
self.Elements().Length() as u32
|
||||
self.Elements().Length()
|
||||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/#dom-form-item
|
||||
|
|
|
@ -2155,7 +2155,7 @@ impl HTMLInputElement {
|
|||
.map(|time| time.and_utc().timestamp_millis() as f64),
|
||||
InputType::Time => match value.parse_time_string() {
|
||||
Some((hours, minutes, seconds)) => {
|
||||
Some((seconds as f64 + 60.0 * minutes as f64 + 3600.0 * hours as f64) * 1000.0)
|
||||
Some((seconds + 60.0 * minutes as f64 + 3600.0 * hours as f64) * 1000.0)
|
||||
},
|
||||
_ => None,
|
||||
},
|
||||
|
@ -2543,7 +2543,7 @@ impl VirtualMethods for HTMLInputElement {
|
|||
let TextIndexResponse(index) =
|
||||
window.text_index_query(self.upcast::<Node>(), point_in_target);
|
||||
if let Some(i) = index {
|
||||
self.textinput.borrow_mut().set_edit_point_index(i as usize);
|
||||
self.textinput.borrow_mut().set_edit_point_index(i);
|
||||
// trigger redraw
|
||||
self.upcast::<Node>().dirty(NodeDamage::OtherNodeDamage);
|
||||
event.PreventDefault();
|
||||
|
|
|
@ -2334,7 +2334,7 @@ impl HTMLMediaElementMethods for HTMLMediaElement {
|
|||
if let Some(ref player) = *self.player.borrow() {
|
||||
if let Ok(ranges) = player.lock().unwrap().buffered() {
|
||||
for range in ranges {
|
||||
let _ = buffered.add(range.start as f64, range.end as f64);
|
||||
let _ = buffered.add(range.start, range.end);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2504,7 +2504,7 @@ impl MicrotaskRunnable for MediaElementMicrotask {
|
|||
elem.resource_selection_algorithm_sync(base_url.clone());
|
||||
}
|
||||
},
|
||||
&MediaElementMicrotask::PauseIfNotInDocumentTask { ref elem } => {
|
||||
MediaElementMicrotask::PauseIfNotInDocumentTask { elem } => {
|
||||
if !elem.upcast::<Node>().is_connected() {
|
||||
elem.internal_pause_steps();
|
||||
}
|
||||
|
|
|
@ -2803,7 +2803,7 @@ impl NodeMethods for Node {
|
|||
.ranges
|
||||
.drain_to_preceding_text_sibling(&sibling, &node, length);
|
||||
self.ranges
|
||||
.move_to_text_child_at(self, index as u32, &node, length as u32);
|
||||
.move_to_text_child_at(self, index as u32, &node, length);
|
||||
let sibling_cdata = sibling.downcast::<CharacterData>().unwrap();
|
||||
length += sibling_cdata.Length();
|
||||
cdata.append_data(&sibling_cdata.data());
|
||||
|
|
|
@ -172,7 +172,7 @@ impl ChildrenList {
|
|||
pub fn item(&self, index: u32) -> Option<DomRoot<Node>> {
|
||||
// This always start traversing the children from the closest element
|
||||
// among parent's first and last children and the last visited one.
|
||||
let len = self.len() as u32;
|
||||
let len = self.len();
|
||||
if index >= len {
|
||||
return None;
|
||||
}
|
||||
|
|
|
@ -379,8 +379,8 @@ impl PaintWorkletGlobalScope {
|
|||
) -> DrawAPaintImageResult {
|
||||
debug!("Returning an invalid image.");
|
||||
DrawAPaintImageResult {
|
||||
width: size.width as u32,
|
||||
height: size.height as u32,
|
||||
width: size.width,
|
||||
height: size.height,
|
||||
format: PixelFormat::BGRA8,
|
||||
image_key: None,
|
||||
missing_image_urls,
|
||||
|
|
|
@ -497,7 +497,7 @@ impl ExternalUnderlyingSourceController {
|
|||
fn get_chunk_with_length(&self, length: usize) -> Vec<u8> {
|
||||
let mut buffer = self.buffer.borrow_mut();
|
||||
let buffer_len = buffer.len();
|
||||
assert!(buffer_len >= length as usize);
|
||||
assert!(buffer_len >= length);
|
||||
buffer.split_off(buffer_len - length)
|
||||
}
|
||||
|
||||
|
|
|
@ -40,7 +40,7 @@ impl TextTrackList {
|
|||
pub fn item(&self, idx: usize) -> Option<DomRoot<TextTrack>> {
|
||||
self.dom_tracks
|
||||
.borrow()
|
||||
.get(idx as usize)
|
||||
.get(idx)
|
||||
.map(|t| DomRoot::from_ref(&**t))
|
||||
}
|
||||
|
||||
|
|
|
@ -765,7 +765,7 @@ impl<'a> WebGLValidator for TexStorageValidator<'a> {
|
|||
return Err(TexImageValidationError::InvalidTextureFormat);
|
||||
}
|
||||
|
||||
let max_level = log2(cmp::max(width, height) as u32) + 1;
|
||||
let max_level = log2(cmp::max(width, height)) + 1;
|
||||
if level > max_level {
|
||||
context.webgl_error(InvalidOperation);
|
||||
return Err(TexImageValidationError::LevelTooHigh);
|
||||
|
|
|
@ -2664,15 +2664,7 @@ impl WebGLRenderingContextMethods for WebGLRenderingContext {
|
|||
// NB: TexImage2D depth is always equal to 1
|
||||
handle_potential_webgl_error!(
|
||||
self,
|
||||
texture.initialize(
|
||||
target,
|
||||
width as u32,
|
||||
height as u32,
|
||||
1,
|
||||
internal_format,
|
||||
level as u32,
|
||||
None
|
||||
)
|
||||
texture.initialize(target, width, height, 1, internal_format, level, None)
|
||||
);
|
||||
|
||||
let msg = WebGLCommand::CopyTexImage2D(
|
||||
|
|
|
@ -285,7 +285,7 @@ impl<'dom, LayoutDataType: LayoutDataTrait> ServoThreadSafeLayoutNode<'dom, Layo
|
|||
/// Creates a new `ServoThreadSafeLayoutNode` from the given `ServoLayoutNode`.
|
||||
pub fn new(node: ServoLayoutNode<'dom, LayoutDataType>) -> Self {
|
||||
ServoThreadSafeLayoutNode {
|
||||
node: node,
|
||||
node,
|
||||
pseudo: PseudoElementType::Normal,
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1658,7 +1658,7 @@ fn fetch_single_module_script(
|
|||
data: vec![],
|
||||
metadata: None,
|
||||
url: url.clone(),
|
||||
destination: destination,
|
||||
destination,
|
||||
options,
|
||||
status: Ok(()),
|
||||
resource_timing: ResourceFetchTiming::new(ResourceTimingType::Resource),
|
||||
|
|
|
@ -700,11 +700,7 @@ pub fn get_reports(cx: *mut RawJSContext, path_seg: String) -> Vec<Report> {
|
|||
let mut report = |mut path_suffix, kind, size| {
|
||||
let mut path = path![path_seg, "js"];
|
||||
path.append(&mut path_suffix);
|
||||
reports.push(Report {
|
||||
path,
|
||||
kind,
|
||||
size: size as usize,
|
||||
})
|
||||
reports.push(Report { path, kind, size })
|
||||
};
|
||||
|
||||
// A note about possibly confusing terminology: the JS GC "heap" is allocated via
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue