Skip to content

Commit 277674d

Browse files
avoid extra allocation by mutating the var
1 parent 2c85b9b commit 277674d

File tree

2 files changed

+9
-9
lines changed

2 files changed

+9
-9
lines changed

src/event/format/json.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -268,9 +268,9 @@ fn rename_json_keys(values: Vec<Value>) -> Vec<Value> {
268268
if let Value::Object(map) = value {
269269
let new_map: serde_json::Map<String, Value> = map
270270
.into_iter()
271-
.map(|(key, val)| {
272-
let new_key = super::normalize_field_name(&key);
273-
(new_key, val)
271+
.map(|(mut key, val)| {
272+
super::normalize_field_name(&mut key);
273+
(key, val)
274274
})
275275
.collect();
276276
Value::Object(new_map)
@@ -292,7 +292,8 @@ fn fields_mismatch(
292292
continue;
293293
}
294294
// Normalize field name to match schema transformation
295-
let lookup_name = super::normalize_field_name(name);
295+
let mut lookup_name = name.to_string();
296+
super::normalize_field_name(&mut lookup_name);
296297
let Some(field) = get_field(schema, &lookup_name) else {
297298
return true;
298299
};

src/event/format/mod.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,9 @@ type EventSchema = Vec<Arc<Field>>;
6060
/// Normalizes a field name by replacing leading '@' with '_'.
6161
/// Fields starting with '@' are renamed to start with '_'.
6262
#[inline]
63-
pub fn normalize_field_name(name: &str) -> String {
63+
pub fn normalize_field_name(name: &mut String) {
6464
if let Some(stripped) = name.strip_prefix('@') {
65-
format!("_{}", stripped)
66-
} else {
67-
name.to_string()
65+
*name = format!("_{}", stripped);
6866
}
6967
}
7068

@@ -347,7 +345,8 @@ pub fn override_data_type(
347345
.iter()
348346
.map(|field| {
349347
// Normalize field names - replace '@' prefix with '_'
350-
let field_name = normalize_field_name(field.name());
348+
let mut field_name = field.name().to_string();
349+
normalize_field_name(&mut field_name);
351350
match (schema_version, map.get(field.name())) {
352351
// in V1 for new fields in json named "time"/"date" or such and having inferred
353352
// type string, that can be parsed as timestamp, use the timestamp type.

0 commit comments

Comments
 (0)