mirror of
https://github.com/servo/servo.git
synced 2025-08-06 06:00:15 +01:00
style: Avoid writing into the empty array header.
Differential Revision: https://phabricator.services.mozilla.com/D55291
This commit is contained in:
parent
f89c31120f
commit
80ac4d2ff2
1 changed files with 7 additions and 2 deletions
|
@ -89,9 +89,11 @@ impl<T> nsTArray<T> {
|
||||||
pub unsafe fn set_len(&mut self, len: u32) {
|
pub unsafe fn set_len(&mut self, len: u32) {
|
||||||
// this can leak
|
// this can leak
|
||||||
debug_assert!(len >= self.len() as u32);
|
debug_assert!(len >= self.len() as u32);
|
||||||
|
if self.len() == len as usize {
|
||||||
|
return;
|
||||||
|
}
|
||||||
self.ensure_capacity(len as usize);
|
self.ensure_capacity(len as usize);
|
||||||
let header = self.header_mut();
|
self.header_mut().mLength = len;
|
||||||
header.mLength = len;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Resizes an array containing only POD elements
|
/// Resizes an array containing only POD elements
|
||||||
|
@ -103,6 +105,9 @@ impl<T> nsTArray<T> {
|
||||||
where
|
where
|
||||||
T: Copy,
|
T: Copy,
|
||||||
{
|
{
|
||||||
|
if self.len() == len as usize {
|
||||||
|
return;
|
||||||
|
}
|
||||||
self.ensure_capacity(len as usize);
|
self.ensure_capacity(len as usize);
|
||||||
let header = self.header_mut();
|
let header = self.header_mut();
|
||||||
header.mLength = len;
|
header.mLength = len;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue