Auto merge of #21598 - kingdido999:master, r=jdm

Format components fallible and geometry #21373

```bash
rustfmt components/fallible/*.rs
rustfmt components/geometry/*.rs
```

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/21598)
<!-- Reviewable:end -->
This commit is contained in:
bors-servo 2018-09-04 07:36:23 -04:00 committed by GitHub
commit 587cbd079e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 36 additions and 33 deletions

View file

@ -18,7 +18,6 @@ pub trait FallibleVec<T> {
fn try_push(&mut self, value: T) -> Result<(), FailedAllocationError>;
}
/////////////////////////////////////////////////////////////////
// Vec
@ -52,14 +51,14 @@ fn try_double_vec<T>(vec: &mut Vec<T>) -> Result<(), FailedAllocationError> {
let new_cap: usize = if old_cap == 0 {
4
} else {
old_cap.checked_mul(2).ok_or(FailedAllocationError::new(
"capacity overflow for Vec",
))?
old_cap
.checked_mul(2)
.ok_or(FailedAllocationError::new("capacity overflow for Vec"))?
};
let new_size_bytes = new_cap.checked_mul(mem::size_of::<T>()).ok_or(
FailedAllocationError::new("capacity overflow for Vec"),
)?;
let new_size_bytes = new_cap
.checked_mul(mem::size_of::<T>())
.ok_or(FailedAllocationError::new("capacity overflow for Vec"))?;
let new_ptr = unsafe {
if old_cap == 0 {
@ -75,15 +74,12 @@ fn try_double_vec<T>(vec: &mut Vec<T>) -> Result<(), FailedAllocationError> {
));
}
let new_vec = unsafe {
Vec::from_raw_parts(new_ptr as *mut T, old_len, new_cap)
};
let new_vec = unsafe { Vec::from_raw_parts(new_ptr as *mut T, old_len, new_cap) };
mem::forget(mem::replace(vec, new_vec));
Ok(())
}
/////////////////////////////////////////////////////////////////
// SmallVec
@ -107,8 +103,7 @@ impl<T: Array> FallibleVec<T::Item> for SmallVec<T> {
#[cfg(feature = "known_system_malloc")]
#[inline(never)]
#[cold]
fn try_double_small_vec<T>(svec: &mut SmallVec<T>)
-> Result<(), FailedAllocationError>
fn try_double_small_vec<T>(svec: &mut SmallVec<T>) -> Result<(), FailedAllocationError>
where
T: Array,
{
@ -122,20 +117,20 @@ where
let new_cap: usize = if old_cap == 0 {
4
} else {
old_cap.checked_mul(2).ok_or(FailedAllocationError::new(
"capacity overflow for SmallVec",
))?
old_cap
.checked_mul(2)
.ok_or(FailedAllocationError::new("capacity overflow for SmallVec"))?
};
// This surely shouldn't fail, if |old_cap| was previously accepted as a
// valid value. But err on the side of caution.
let old_size_bytes = old_cap.checked_mul(mem::size_of::<T>()).ok_or(
FailedAllocationError::new("capacity overflow for SmallVec"),
)?;
let old_size_bytes = old_cap
.checked_mul(mem::size_of::<T>())
.ok_or(FailedAllocationError::new("capacity overflow for SmallVec"))?;
let new_size_bytes = new_cap.checked_mul(mem::size_of::<T>()).ok_or(
FailedAllocationError::new("capacity overflow for SmallVec"),
)?;
let new_size_bytes = new_cap
.checked_mul(mem::size_of::<T>())
.ok_or(FailedAllocationError::new("capacity overflow for SmallVec"))?;
let new_ptr;
if svec.spilled() {
@ -149,8 +144,7 @@ where
unsafe {
new_ptr = alloc::alloc(new_size_bytes, 0);
if !new_ptr.is_null() && old_size_bytes > 0 {
copy_nonoverlapping(old_ptr as *const u8,
new_ptr as *mut u8, old_size_bytes);
copy_nonoverlapping(old_ptr as *const u8, new_ptr as *mut u8, old_size_bytes);
}
}
}
@ -161,9 +155,7 @@ where
));
}
let new_vec = unsafe {
Vec::from_raw_parts(new_ptr as *mut T::Item, old_len, new_cap)
};
let new_vec = unsafe { Vec::from_raw_parts(new_ptr as *mut T::Item, old_len, new_cap) };
let new_svec = SmallVec::from_vec(new_vec);
mem::forget(mem::replace(svec, new_svec));

View file

@ -5,8 +5,9 @@
extern crate app_units;
extern crate euclid;
extern crate malloc_size_of;
#[macro_use]
extern crate malloc_size_of_derive;
extern crate style_traits;
#[macro_use] extern crate malloc_size_of_derive;
extern crate webrender_api;
use app_units::{Au, MAX_AU, MIN_AU};
@ -48,7 +49,7 @@ impl MaxRect for Rect<Au> {
fn max_rect() -> Rect<Au> {
Rect::new(
Point2D::new(MIN_AU / 2, MIN_AU / 2),
Size2D::new(MAX_AU, MAX_AU)
Size2D::new(MAX_AU, MAX_AU),
)
}
}
@ -64,12 +65,22 @@ impl MaxRect for LayoutRect {
/// A helper function to convert a rect of `f32` pixels to a rect of app units.
pub fn f32_rect_to_au_rect(rect: Rect<f32>) -> Rect<Au> {
Rect::new(Point2D::new(Au::from_f32_px(rect.origin.x), Au::from_f32_px(rect.origin.y)),
Size2D::new(Au::from_f32_px(rect.size.width), Au::from_f32_px(rect.size.height)))
Rect::new(
Point2D::new(
Au::from_f32_px(rect.origin.x),
Au::from_f32_px(rect.origin.y),
),
Size2D::new(
Au::from_f32_px(rect.size.width),
Au::from_f32_px(rect.size.height),
),
)
}
/// A helper function to convert a rect of `Au` pixels to a rect of f32 units.
pub fn au_rect_to_f32_rect(rect: Rect<Au>) -> Rect<f32> {
Rect::new(Point2D::new(rect.origin.x.to_f32_px(), rect.origin.y.to_f32_px()),
Size2D::new(rect.size.width.to_f32_px(), rect.size.height.to_f32_px()))
Rect::new(
Point2D::new(rect.origin.x.to_f32_px(), rect.origin.y.to_f32_px()),
Size2D::new(rect.size.width.to_f32_px(), rect.size.height.to_f32_px()),
)
}