Skip to content

Add support for multi-threaded xpath evaluation#191

Open
maartendeprez wants to merge 1 commit intoKWARC:masterfrom
maartendeprez:add-readonly-xpath-support
Open

Add support for multi-threaded xpath evaluation#191
maartendeprez wants to merge 1 commit intoKWARC:masterfrom
maartendeprez:add-readonly-xpath-support

Conversation

@maartendeprez
Copy link

The readonly module provides support for multi-threaded read-only operations over a parsed document. However, the findnodes method takes a shared reference to a Document, which is not readonly and therefore not Send + Sync. This makes it impossible, currently, to evaluate xpaths over the document from multiple threads.

This PR changes that by introducing a read-only version of Document, Context and Object, as well as a findnodes_readonly method on RoNode.

@dginev
Copy link
Member

dginev commented Mar 20, 2026

Thank you, this appears to be a very useful extension.

Could I also request that you mirror our one findnodes test here:

#[test]
/// Test that the dual findnodes interfaces are operational
fn findnodes_interfaces() {
let parser = Parser::default_html();
let doc_result = parser.parse_file("tests/resources/file02.xml");
assert!(doc_result.is_ok());
let doc = doc_result.unwrap();
// Xpath interface
let mut context = Context::new(&doc).unwrap();
let body = context.evaluate("/html/body").unwrap().get_nodes_as_vec();
let p_result = context.findnodes("p", body.first());
assert!(p_result.is_ok());
let p = p_result.unwrap();
assert_eq!(p.len(), 1);
// Node interface
let body_node = body.first().unwrap();
let p2_result = body_node.findnodes("p");
assert!(p2_result.is_ok());
let p2 = p2_result.unwrap();
assert_eq!(p2.len(), 1);
}

With a similar entry inside readonly_tests.rs ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants