From 8c15fb0288195c0c4ab9420e40e870b67c12e7e6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gabriel=20N=C3=BCtzi?= Date: Fri, 12 Jul 2024 17:54:14 +0200 Subject: [PATCH] fix: remove from first-pass since no benefit --- src/main.rs | 2 +- src/pass_first.rs | 46 +++++++++++----------------------------------- src/pass_second.rs | 2 +- 3 files changed, 13 insertions(+), 37 deletions(-) diff --git a/src/main.rs b/src/main.rs index 3588697..f69a2a8 100644 --- a/src/main.rs +++ b/src/main.rs @@ -111,7 +111,7 @@ fn main() { match cli.command { Subcommands::Index(args) => { info!(log, "Args: {:?}", args); - create_type_map(&args.input, &args.output, parallelize) + create_type_map(&args.input, &args.output) } Subcommands::Pseudo(args) => { info!(log, "Args: {:?}", args); diff --git a/src/pass_first.rs b/src/pass_first.rs index d5bc602..039edce 100644 --- a/src/pass_first.rs +++ b/src/pass_first.rs @@ -1,7 +1,6 @@ -use rayon::prelude::*; use rio_api::parser::TriplesParser; use rio_turtle::TurtleError; -use std::{io::Write, path::Path, sync::Mutex}; +use std::{io::Write, path::Path}; use crate::{ io, @@ -21,42 +20,19 @@ fn index_triple(t: Triple, out: &mut impl Write) { } } -pub fn create_type_map(input: &Path, output: &Path, parallel: bool) { +pub fn create_type_map(input: &Path, output: &Path) { let buf_in = io::get_reader(input); let mut buf_out = io::get_writer(output); let mut triples = io::parse_ntriples(buf_in); - if parallel { - // Make a parallel triple iterator over `rdf_types::Triple`. - // We have to wrap the `buf_out` with a `Mutex` to make it - // writable by multiple threads. - // NOTE: Weird `rio_api::into_iter` implementation, why does it use a full-blown - // `Vec`, this could be simpler. - // - let buf_out = Mutex::new(buf_out); - let it = triples - .into_iter(|t: TripleView| Result::::Ok(t.into())) - .par_bridge(); - - // Iterate in parallel over the triples. - it.for_each(|r| match r { - Err(e) => panic!("Parsing error occured: {e}"), - Ok(t) => { - let mut guard = buf_out.lock().unwrap(); - index_triple(t, guard.by_ref()); - } - }); - } else { - // Run the loop single-threaded. - while !triples.is_end() { - let _ = triples - .parse_step(&mut |t: TripleView| { - index_triple(t.into(), &mut buf_out); - Result::<(), TurtleError>::Ok(()) - }) - .inspect_err(|e| { - panic!("Parsing error occured: {e}"); - }); - } + while !triples.is_end() { + let _ = triples + .parse_step(&mut |t: TripleView| { + index_triple(t.into(), &mut buf_out); + Result::<(), TurtleError>::Ok(()) + }) + .inspect_err(|e| { + panic!("Parsing error occured: {e}"); + }); } } diff --git a/src/pass_second.rs b/src/pass_second.rs index 63cb0b1..25df1e8 100644 --- a/src/pass_second.rs +++ b/src/pass_second.rs @@ -93,7 +93,7 @@ pub fn pseudonymize_graph( // We have to wrap the `buf_out` with a `Mutex` to make it // writable by multiple threads. // Also: The Mutex will be double locked 🤔 - // if `stdout` is used since the + // if `stdout` is used since its locked internally. // std::io::stdout() is already locked internall. // // NOTE: Weird `rio_api::into_iter` implementation, why does it use a full-blown