Skip to content

Commit

Permalink
Added clear method on HashMapContext's variables and functions fields. (
Browse files Browse the repository at this point in the history
#156)

I've the below use case where numerous allocations are happening and
hoping to reduce the impact of those re-allocations using the _clear_
method on the fields of `HashMapContext`:

There are 1000s of transactions with each transaction having about 40
fields. Let's say field 5 and field 30 are sent from source as optional
Boolean type (`Option<bool>`), which would mean certain transaction
could have a boolean value and other transactions would have null value.
I cannot use a default boolean value here. Since once the
`HashMapContext` variables are created, their types can no longer be
changed. Therefore, I have re-initiate the HashMapContext ```let mut
context = HashMapContext::new();``` after every transaction and does the
re-allocation.
  • Loading branch information
ISibboI authored Nov 17, 2023
2 parents 5a71721 + e4b1bc7 commit e585859
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/context/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,16 @@ impl HashMapContext {
pub fn new() -> Self {
Default::default()
}

/// Clears the [variables] HashMap so it can re-populated if needed

Check warning on line 189 in src/context/mod.rs

View workflow job for this annotation

GitHub Actions / Check, test, doc, format and lint with all features (ubuntu-latest, beta)

unresolved link to `variables`

Check warning on line 189 in src/context/mod.rs

View workflow job for this annotation

GitHub Actions / Check, test, doc, format and lint with all features (ubuntu-latest, nightly)

unresolved link to `variables`

Check warning on line 189 in src/context/mod.rs

View workflow job for this annotation

GitHub Actions / Check, test, doc, format and lint with all features (ubuntu-latest, stable)

unresolved link to `variables`
pub fn clear_variables_map(&mut self) {
self.variables.clear()
}

/// Clears the [functions] HashMap so it can re-populated if needed

Check warning on line 194 in src/context/mod.rs

View workflow job for this annotation

GitHub Actions / Check, test, doc, format and lint with all features (ubuntu-latest, beta)

unresolved link to `functions`

Check warning on line 194 in src/context/mod.rs

View workflow job for this annotation

GitHub Actions / Check, test, doc, format and lint with all features (ubuntu-latest, nightly)

unresolved link to `functions`

Check warning on line 194 in src/context/mod.rs

View workflow job for this annotation

GitHub Actions / Check, test, doc, format and lint with all features (ubuntu-latest, stable)

unresolved link to `functions`
pub fn clear_functions_map(&mut self) {
self.functions.clear()
}
}

impl Context for HashMapContext {
Expand Down

0 comments on commit e585859

Please sign in to comment.