Store nsDynamicAtom's chars after the end of the object.

This reduces memory usage because we only need one allocation instead of two
for the dynamic atom and its chars, and because we don't need to store a
refcount and a size. It precludes sharing of chars between dynamic atoms, but
we weren't benefiting much from that anyway.

This reduces per-process memory usage by up to several hundred KiB on my
Linux64 box.

One consequence of this change is that we need to allocate + copy in
DOMString::SetKnownLiveAtom(), which could make some things slower.

Bug: 1447951
Reviewed-by: froydnj
This commit is contained in:
Nicholas Nethercote 2018-06-22 09:38:42 +10:00 committed by Emilio Cobos Álvarez
parent ce7b6616fb
commit 46e572a497
No known key found for this signature in database
GPG key ID: 056B727BB9C1027C

View file

@ -122,7 +122,8 @@ impl WeakAtom {
unsafe { u8_ptr.offset(string_offset) as *const u16 }
} else {
let atom_ptr = self.as_ptr() as *const nsDynamicAtom;
unsafe { (*(atom_ptr)).mString }
// Dynamic atom chars are stored at the end of the object.
unsafe { atom_ptr.offset(1) as *const u16 }
};
unsafe { slice::from_raw_parts(string, self.len() as usize) }
}