Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimisations and `document` request and rule handling fixes #35

Merged
merged 10 commits into from Jun 28, 2019

adds token buffer pool wrapper for deserialization backwards-compatib…

…ility
  • Loading branch information
AndriusA committed Jun 19, 2019
commit d9a1630b8d9d82d0342f3dad9452c9a51f04c787
@@ -57,12 +57,16 @@ impl From<FilterError> for BlockerError {
}
}

struct TokenPool {
pub pool: Pool<Vec<utils::Hash>>
}

fn hash_pool<'de, D>(_deserializer: D) -> Result<Pool<Vec<utils::Hash>>, D::Error>
where
D: Deserializer<'de>,
{
Ok(Pool::new(1, || Vec::with_capacity(utils::TOKENS_BUFFER_SIZE)))
impl Default for TokenPool {
fn default() -> TokenPool {
TokenPool {
pool: Pool::new(1, || Vec::with_capacity(utils::TOKENS_BUFFER_SIZE))
}
}
}

#[derive(Serialize, Deserialize)]
@@ -89,9 +93,9 @@ pub struct Blocker {
load_network_filters: bool,

#[serde(default)]
resources: Resources
#[serde(skip_serializing, deserialize_with = "hash_pool")]
pool: Pool<Vec<utils::Hash>>,
resources: Resources,
#[serde(skip_serializing, skip_deserializing)]
pool: TokenPool,
}

impl Blocker {
@@ -112,7 +116,7 @@ impl Blocker {
#[cfg(feature = "metrics")]
print!("importants\t");

let mut request_tokens = self.pool.pull().unwrap();
let mut request_tokens = self.pool.pool.pull().unwrap();
request.get_tokens(&mut request_tokens);

let filter = self
@@ -272,8 +276,8 @@ impl Blocker {
load_cosmetic_filters: options.load_cosmetic_filters,
load_network_filters: options.load_network_filters,

resources: Resources::default()
pool: Pool::new(1, || Vec::with_capacity(utils::TOKENS_BUFFER_SIZE)),
resources: Resources::default(),
pool: TokenPool::default(),
}
}

ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.