MCPcopy Create free account
hub / github.com/argumentcomputer/ix / rs_mt_parallel_decode_exprs

Function rs_mt_parallel_decode_exprs

crates/ffi/src/refcount.rs:324–358  ·  view source on GitHub ↗
(
  arr: LeanArray<LeanBorrowed<'_>>,
  n_threads: usize,
)

Source from the content-addressed store, hash-verified

322/// Each thread decodes all exprs and counts nodes.
323#[unsafe(no_mangle)]
324pub extern "C" fn rs_mt_parallel_decode_exprs(
325 arr: LeanArray<LeanBorrowed<'_>>,
326 n_threads: usize,
327) -> LeanOwned {
328 fn count_expr_nodes(expr: &LeanIxExpr<impl LeanRef>) -> u64 {
329 let ctor = expr.as_ctor();
330 match ctor.tag() {
331 5 => {
332 // app
333 1 + count_expr_nodes(&LeanIxExpr(ctor.get(0)))
334 + count_expr_nodes(&LeanIxExpr(ctor.get(1)))
335 },
336 _ => 1,
337 }
338 }
339
340 let shared = LeanShared::new(arr.inner().to_owned_ref());
341
342 let handles: Vec<_> = (0..n_threads)
343 .map(|_| {
344 let shared_clone = shared.clone();
345 thread::spawn(move || {
346 let borrowed_arr = shared_clone.borrow().as_array();
347 let mut total: u64 = 0;
348 for elem in borrowed_arr.iter() {
349 total += count_expr_nodes(&LeanIxExpr(elem));
350 }
351 total
352 })
353 })
354 .collect();
355
356 let total: u64 = handles.into_iter().map(|h| h.join().unwrap()).sum();
357 LeanNat::from_nat(&Nat::from(total)).into()
358}
359
360/// Parallel roundtrip: mark array of Names as MT, each thread decodes
361/// all names and rebuilds them. Returns an array of rebuilt names from

Callers

nothing calls this directly

Calls 5

count_expr_nodesFunction · 0.85
as_arrayMethod · 0.80
joinMethod · 0.80
cloneMethod · 0.45
iterMethod · 0.45

Tested by

no test coverage detected