forked from mirrors/gecko-dev
		
	Servo currently uses `heapsize`, but Stylo/Gecko use `malloc_size_of`. `malloc_size_of` is better -- it handles various cases that `heapsize` does not -- so this patch changes Servo to use `malloc_size_of`. This patch makes the following changes to the `malloc_size_of` crate. - Adds `MallocSizeOf` trait implementations for numerous types, some built-in (e.g. `VecDeque`), some external and Servo-only (e.g. `string_cache`). - Makes `enclosing_size_of_op` optional, because vanilla jemalloc doesn't support that operation. - For `HashSet`/`HashMap`, falls back to a computed estimate when `enclosing_size_of_op` isn't available. - Adds an extern "C" `malloc_size_of` function that does the actual heap measurement; this is based on the same functions from the `heapsize` crate. This patch makes the following changes elsewhere. - Converts all the uses of `heapsize` to instead use `malloc_size_of`. - Disables the "heapsize"/"heap_size" feature for the external crates that provide it. - Removes the `HeapSizeOf` implementation from `hashglobe`. - Adds `ignore` annotations to a few `Rc`/`Arc`, because `malloc_size_of` doesn't derive those types, unlike `heapsize`. <!-- Please describe your changes on the following line: --> --- <!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: --> - [X] `./mach build -d` does not report any errors - [X] `./mach test-tidy` does not report any errors - [ ] These changes fix https://bugzilla.mozilla.org/show_bug.cgi?id=1409255 <!-- Either: --> - [ ] There are tests for these changes OR - [ ] These changes do not require tests because testing is on the Gecko side. <!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.--> <!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. --> Source-Repo: https://github.com/servo/servo Source-Revision: 4c538b642e4bdfbf42c522c5a59c258a6d14546e --HG-- extra : subtree_source : https%3A//hg.mozilla.org/projects/converted-servo-linear extra : subtree_revision : f9a6feed1088d0b0be2b55d7f0c2ec9c594ac33b
		
			
				
	
	
		
			87 lines
		
	
	
	
		
			2.5 KiB
		
	
	
	
		
			Rust
		
	
	
	
	
	
			
		
		
	
	
			87 lines
		
	
	
	
		
			2.5 KiB
		
	
	
	
		
			Rust
		
	
	
	
	
	
/* This Source Code Form is subject to the terms of the Mozilla Public
 | 
						|
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 | 
						|
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 | 
						|
 | 
						|
#![allow(unrooted_must_root)]
 | 
						|
 | 
						|
use dom::bindings::root::{Dom, DomRoot};
 | 
						|
use dom::bindings::trace::JSTraceable;
 | 
						|
use dom::document::Document;
 | 
						|
use dom::htmlscriptelement::HTMLScriptElement;
 | 
						|
use dom::node::Node;
 | 
						|
use dom::servoparser::Sink;
 | 
						|
use js::jsapi::JSTracer;
 | 
						|
use servo_url::ServoUrl;
 | 
						|
use xml5ever::buffer_queue::BufferQueue;
 | 
						|
use xml5ever::tokenizer::XmlTokenizer;
 | 
						|
use xml5ever::tree_builder::{Tracer as XmlTracer, XmlTreeBuilder};
 | 
						|
 | 
						|
#[derive(JSTraceable, MallocSizeOf)]
 | 
						|
#[must_root]
 | 
						|
pub struct Tokenizer {
 | 
						|
    #[ignore_malloc_size_of = "Defined in xml5ever"]
 | 
						|
    inner: XmlTokenizer<XmlTreeBuilder<Dom<Node>, Sink>>,
 | 
						|
}
 | 
						|
 | 
						|
impl Tokenizer {
 | 
						|
    pub fn new(document: &Document, url: ServoUrl) -> Self {
 | 
						|
        let sink = Sink {
 | 
						|
            base_url: url,
 | 
						|
            document: Dom::from_ref(document),
 | 
						|
            current_line: 1,
 | 
						|
            script: Default::default(),
 | 
						|
        };
 | 
						|
 | 
						|
        let tb = XmlTreeBuilder::new(sink, Default::default());
 | 
						|
        let tok = XmlTokenizer::new(tb, Default::default());
 | 
						|
 | 
						|
        Tokenizer {
 | 
						|
            inner: tok,
 | 
						|
        }
 | 
						|
    }
 | 
						|
 | 
						|
    pub fn feed(&mut self, input: &mut BufferQueue) -> Result<(), DomRoot<HTMLScriptElement>> {
 | 
						|
        if !input.is_empty() {
 | 
						|
            while let Some(chunk) = input.pop_front() {
 | 
						|
                self.inner.feed(chunk);
 | 
						|
                if let Some(script) = self.inner.sink.sink.script.take() {
 | 
						|
                    return Err(script);
 | 
						|
                }
 | 
						|
            }
 | 
						|
        } else {
 | 
						|
            self.inner.run();
 | 
						|
            if let Some(script) = self.inner.sink.sink.script.take() {
 | 
						|
                return Err(script);
 | 
						|
            }
 | 
						|
        }
 | 
						|
        Ok(())
 | 
						|
    }
 | 
						|
 | 
						|
    pub fn end(&mut self) {
 | 
						|
        self.inner.end()
 | 
						|
    }
 | 
						|
 | 
						|
    pub fn url(&self) -> &ServoUrl {
 | 
						|
        &self.inner.sink.sink.base_url
 | 
						|
    }
 | 
						|
}
 | 
						|
 | 
						|
#[allow(unsafe_code)]
 | 
						|
unsafe impl JSTraceable for XmlTokenizer<XmlTreeBuilder<Dom<Node>, Sink>> {
 | 
						|
    unsafe fn trace(&self, trc: *mut JSTracer) {
 | 
						|
        struct Tracer(*mut JSTracer);
 | 
						|
        let tracer = Tracer(trc);
 | 
						|
 | 
						|
        impl XmlTracer for Tracer {
 | 
						|
            type Handle = Dom<Node>;
 | 
						|
            #[allow(unrooted_must_root)]
 | 
						|
            fn trace_handle(&self, node: &Dom<Node>) {
 | 
						|
                unsafe { node.trace(self.0); }
 | 
						|
            }
 | 
						|
        }
 | 
						|
 | 
						|
        let tree_builder = &self.sink;
 | 
						|
        tree_builder.trace_handles(&tracer);
 | 
						|
        tree_builder.sink.trace(trc);
 | 
						|
    }
 | 
						|
}
 |