Skip to content

Commit

Permalink
perf: remove slow rayon operation
Browse files Browse the repository at this point in the history
  • Loading branch information
Banyc committed Dec 29, 2023
1 parent ad2f59b commit cf65610
Showing 1 changed file with 1 addition and 3 deletions.
4 changes: 1 addition & 3 deletions common/src/crypto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ use std::{
};

use base64::prelude::*;
use rayon::prelude::*;
use serde::{Deserialize, Serialize};
use thiserror::Error;

Expand Down Expand Up @@ -64,15 +63,14 @@ impl XorCryptoCursor {
if self.key.is_empty() {
return;
}
buf.par_iter_mut().enumerate().for_each(|(i, b)| {
buf.iter_mut().enumerate().for_each(|(i, b)| {
let i = i + self.pos;
let xor_b = *b ^ self.key[i % self.key.len()];
*b = xor_b;
});
self.pos = (self.pos + buf.len()) % self.key.len();
}

/// Slow.
pub fn xor_to<W>(&mut self, buf: &[u8], to: &mut W) -> io::Result<()>
where
W: Write,
Expand Down

0 comments on commit cf65610

Please sign in to comment.