From 46e572a497166a7dd0cd1ce99b5e0e2e8f5639af Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Fri, 22 Jun 2018 09:38:42 +1000 Subject: [PATCH] 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 --- components/style/gecko_string_cache/mod.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/components/style/gecko_string_cache/mod.rs b/components/style/gecko_string_cache/mod.rs index 297599e20808..b0c8750265b7 100644 --- a/components/style/gecko_string_cache/mod.rs +++ b/components/style/gecko_string_cache/mod.rs @@ -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) } }