Skip to content

Commit

Permalink
Move rayon utils into their own file
Browse files Browse the repository at this point in the history
  • Loading branch information
ergrelet committed Mar 10, 2024
1 parent 30f2f19 commit 5cd70ed
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 48 deletions.
49 changes: 1 addition & 48 deletions resym_core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,56 +4,9 @@ mod error;
pub mod frontend;
pub mod pdb_file;
pub mod pdb_types;
pub mod rayon_utils;
pub mod syntax_highlighting;

pub use error::*;

const PKG_VERSION: &str = env!("CARGO_PKG_VERSION");

/// Macro used to switch between iterators depending on rayon's availability
#[macro_export]
#[cfg(not(feature = "rayon"))]
macro_rules! par_iter_if_available {
($expression:expr) => {
$expression.iter()
};
}
#[macro_export]
#[cfg(feature = "rayon")]
macro_rules! par_iter_if_available {
($expression:expr) => {
$expression.par_iter()
};
}

/// Macro used to switch between functions depending on rayon's availability
#[macro_export]
#[cfg(not(feature = "rayon"))]
macro_rules! par_sort_by_if_available {
($expression:expr, $($x:tt)*) => {
$expression.sort_by($($x)*)
};
}
#[macro_export]
#[cfg(feature = "rayon")]
macro_rules! par_sort_by_if_available {
($expression:expr, $($x:tt)*) => {
$expression.par_sort_by($($x)*)
};
}

/// Macro used to switch between `find_any` and `find` depending on rayon's availability
#[macro_export]
#[cfg(not(feature = "rayon"))]
macro_rules! find_any_if_available {
($expression:expr, $($x:tt)*) => {
$expression.iter().find($($x)*)
};
}
#[macro_export]
#[cfg(feature = "rayon")]
macro_rules! find_any_if_available {
($expression:expr, $($x:tt)*) => {
$expression.par_iter().find_any($($x)*)
};
}
47 changes: 47 additions & 0 deletions resym_core/src/rayon_utils.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/// Macro used to switch between iterators depending on rayon's availability
#[macro_export]
#[cfg(not(feature = "rayon"))]
macro_rules! par_iter_if_available {
($expression:expr) => {
$expression.iter()
};
}
#[macro_export]
#[cfg(feature = "rayon")]
macro_rules! par_iter_if_available {
($expression:expr) => {
$expression.par_iter()
};
}

/// Macro used to switch between functions depending on rayon's availability
#[macro_export]
#[cfg(not(feature = "rayon"))]
macro_rules! par_sort_by_if_available {
($expression:expr, $($x:tt)*) => {
$expression.sort_by($($x)*)
};
}
#[macro_export]
#[cfg(feature = "rayon")]
macro_rules! par_sort_by_if_available {
($expression:expr, $($x:tt)*) => {
$expression.par_sort_by($($x)*)
};
}

/// Macro used to switch between `find_any` and `find` depending on rayon's availability
#[macro_export]
#[cfg(not(feature = "rayon"))]
macro_rules! find_any_if_available {
($expression:expr, $($x:tt)*) => {
$expression.iter().find($($x)*)
};
}
#[macro_export]
#[cfg(feature = "rayon")]
macro_rules! find_any_if_available {
($expression:expr, $($x:tt)*) => {
$expression.par_iter().find_any($($x)*)
};
}

0 comments on commit 5cd70ed

Please sign in to comment.