Skip to main content

parse_to_dom

Function parse_to_dom 

Source
pub fn parse_to_dom<'a>(
    src: &'a str,
    initial_capacity: Option<usize>,
) -> Option<Dom<'a>>
Expand description

Parse src into a flat Dom using the portable SWAR classifier.

initial_capacity pre-sizes the tape allocation. Pass None to let the parser decide (equivalent to Some(0), i.e. start with a default-sized Vec). The tape grows automatically so this is only a performance hint.

Returns None if the input is not valid JSON.

For maximum throughput on CPUs with AVX-512BW, use [parse_to_dom_zmm] or the safe wrapper returned by dom_parser.

use asmjson::{parse_to_dom, JsonRef};
let tape = parse_to_dom(r#"{"x":1}"#, None).unwrap();
assert_eq!(tape.root().get("x").as_i64(), Some(1));