Skip to content

Commit

Permalink
aw-transform: Avoid cloning in filter_keyvals
Browse files Browse the repository at this point in the history
  • Loading branch information
johan-bjareholt committed May 31, 2020
1 parent fa842f6 commit 5185b5d
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions aw-transform/src/filter_keyvals.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ use serde_json::value::Value;

use aw_models::Event;

pub fn filter_keyvals(events: Vec<Event>, key: &str, vals: &[Value]) -> Vec<Event> {
pub fn filter_keyvals(mut events: Vec<Event>, key: &str, vals: &[Value]) -> Vec<Event> {
let mut filtered_events = Vec::new();
for event in events {
for event in events.drain(..) {
match event.data.get(key) {
Some(v) => {
for val in vals {
Expand All @@ -15,16 +15,16 @@ pub fn filter_keyvals(events: Vec<Event>, key: &str, vals: &[Value]) -> Vec<Even
}
}
}
None => break,
None => (),
}
}
filtered_events
}

pub fn filter_keyvals_regex(events: Vec<Event>, key: &str, regex: &Regex) -> Vec<Event> {
pub fn filter_keyvals_regex(mut events: Vec<Event>, key: &str, regex: &Regex) -> Vec<Event> {
let mut filtered_events = Vec::new();

for event in events {
for event in events.drain(..) {
match event.data.get(key) {
Some(v) => {
if regex.is_match(v.as_str().unwrap()) {
Expand Down

0 comments on commit 5185b5d

Please sign in to comment.