Skip to content

Commit 5ed46fd

Browse files
authored
ref(relay): Use to_owned instead of to_string. (#4855)
~~AI~~ :shipit: Another W for not using AI, Cursor replaces 105 occurrences for a few dollars and 30 minutes agent, me googling syntax of ripgrep and xargs and writing the regex ~10 minutes and it finds 1000+ more occurrences. Cursor also only did the trivial case (which the regex just does better).
1 parent 52a07a4 commit 5ed46fd

File tree

95 files changed

+1209
-1229
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

95 files changed

+1209
-1229
lines changed

relay-cabi/src/processing.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -401,9 +401,9 @@ pub unsafe extern "C" fn relay_validate_rule_condition(value: *const RelayStr) -
401401
let ret_val = match serde_json::from_str::<RuleCondition>(unsafe { (*value).as_str() }) {
402402
Ok(condition) => {
403403
if condition.supported() {
404-
"".to_string()
404+
"".to_owned()
405405
} else {
406-
"unsupported condition".to_string()
406+
"unsupported condition".to_owned()
407407
}
408408
}
409409
Err(e) => e.to_string(),

relay-cardinality/src/config.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ mod tests {
9797
#[test]
9898
fn test_cardinality_limit_json() {
9999
let limit = CardinalityLimit {
100-
id: "some_id".to_string(),
100+
id: "some_id".to_owned(),
101101
passive: false,
102102
report: false,
103103
window: SlidingWindow {

relay-dynamic-config/src/project.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ impl ProjectConfig {
126126
impl Default for ProjectConfig {
127127
fn default() -> Self {
128128
ProjectConfig {
129-
allowed_domains: vec!["*".to_string()],
129+
allowed_domains: vec!["*".to_owned()],
130130
trusted_relays: vec![],
131131
pii_config: None,
132132
grouping_config: None,

relay-event-normalization/src/event.rs

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -394,7 +394,7 @@ fn normalize_security_report(
394394
return;
395395
}
396396

397-
event.logger.get_or_insert_with(|| "csp".to_string());
397+
event.logger.get_or_insert_with(|| "csp".to_owned());
398398

399399
if let Some(client_ip) = client_ip {
400400
let user = event.user.value_mut().get_or_insert_with(User::default);
@@ -582,7 +582,7 @@ fn normalize_breadcrumbs(event: &mut Event) {
582582
};
583583

584584
if breadcrumb.ty.value().is_empty() {
585-
breadcrumb.ty.set_value(Some("default".to_string()));
585+
breadcrumb.ty.set_value(Some("default".to_owned()));
586586
}
587587
if breadcrumb.level.value().is_none() {
588588
breadcrumb.level.set_value(Some(Level::Info));
@@ -683,13 +683,13 @@ fn normalize_event_tags(event: &mut Event) {
683683

684684
let server_name = std::mem::take(&mut event.server_name);
685685
if server_name.value().is_some() {
686-
let tag_name = "server_name".to_string();
686+
let tag_name = "server_name".to_owned();
687687
tags.insert(tag_name, server_name);
688688
}
689689

690690
let site = std::mem::take(&mut event.site);
691691
if site.value().is_some() {
692-
let tag_name = "site".to_string();
692+
let tag_name = "site".to_owned();
693693
tags.insert(tag_name, site);
694694
}
695695
}
@@ -1005,24 +1005,24 @@ fn normalize_trace_context_tags(event: &mut Event) {
10051005
if let Some(data) = trace_context.data.value() {
10061006
if let Some(lcp_element) = data.lcp_element.value() {
10071007
if !tags.contains("lcp.element") {
1008-
let tag_name = "lcp.element".to_string();
1008+
let tag_name = "lcp.element".to_owned();
10091009
tags.insert(tag_name, Annotated::new(lcp_element.clone()));
10101010
}
10111011
}
10121012
if let Some(lcp_size) = data.lcp_size.value() {
10131013
if !tags.contains("lcp.size") {
1014-
let tag_name = "lcp.size".to_string();
1014+
let tag_name = "lcp.size".to_owned();
10151015
tags.insert(tag_name, Annotated::new(lcp_size.to_string()));
10161016
}
10171017
}
10181018
if let Some(lcp_id) = data.lcp_id.value() {
1019-
let tag_name = "lcp.id".to_string();
1019+
let tag_name = "lcp.id".to_owned();
10201020
if !tags.contains("lcp.id") {
10211021
tags.insert(tag_name, Annotated::new(lcp_id.clone()));
10221022
}
10231023
}
10241024
if let Some(lcp_url) = data.lcp_url.value() {
1025-
let tag_name = "lcp.url".to_string();
1025+
let tag_name = "lcp.url".to_owned();
10261026
if !tags.contains("lcp.url") {
10271027
tags.insert(tag_name, Annotated::new(lcp_url.clone()));
10281028
}
@@ -1134,7 +1134,7 @@ fn normalize_default_attributes(event: &mut Event, meta: &mut Meta, config: &Nor
11341134
// Default required attributes, even if they have errors
11351135
event.errors.get_or_insert_with(Vec::new);
11361136
event.id.get_or_insert_with(EventId::new);
1137-
event.platform.get_or_insert_with(|| "other".to_string());
1137+
event.platform.get_or_insert_with(|| "other".to_owned());
11381138
event.logger.get_or_insert_with(String::new);
11391139
event.extra.get_or_insert_with(Object::new);
11401140
event.level.get_or_insert_with(|| match event_type {
@@ -1504,10 +1504,10 @@ fn get_metric_measurement_unit(measurement_name: &str) -> Option<MetricUnit> {
15041504
/// The snake_case is the key expected by the Sentry UI to aggregate and display in graphs.
15051505
fn normalize_app_start_measurements(measurements: &mut Measurements) {
15061506
if let Some(app_start_cold_value) = measurements.remove("app.start.cold") {
1507-
measurements.insert("app_start_cold".to_string(), app_start_cold_value);
1507+
measurements.insert("app_start_cold".to_owned(), app_start_cold_value);
15081508
}
15091509
if let Some(app_start_warm_value) = measurements.remove("app.start.warm") {
1510-
measurements.insert("app_start_warm".to_string(), app_start_warm_value);
1510+
measurements.insert("app_start_warm".to_owned(), app_start_warm_value);
15111511
}
15121512
}
15131513

@@ -1585,16 +1585,16 @@ mod tests {
15851585

15861586
#[test]
15871587
fn test_normalize_dist_empty() {
1588-
let mut dist = Annotated::new("".to_string());
1588+
let mut dist = Annotated::new("".to_owned());
15891589
normalize_dist(&mut dist);
15901590
assert_eq!(dist.value(), None);
15911591
}
15921592

15931593
#[test]
15941594
fn test_normalize_dist_trim() {
1595-
let mut dist = Annotated::new(" foo ".to_string());
1595+
let mut dist = Annotated::new(" foo ".to_owned());
15961596
normalize_dist(&mut dist);
1597-
assert_eq!(dist.value(), Some(&"foo".to_string()));
1597+
assert_eq!(dist.value(), Some(&"foo".to_owned()));
15981598
}
15991599

16001600
#[test]
@@ -1842,7 +1842,7 @@ mod tests {
18421842
csp: Annotated::from(Csp::default()),
18431843
..Default::default()
18441844
};
1845-
let ipaddr = IpAddr("213.164.1.114".to_string());
1845+
let ipaddr = IpAddr("213.164.1.114".to_owned());
18461846

18471847
let client_ip = Some(&ipaddr);
18481848

@@ -1919,8 +1919,8 @@ mod tests {
19191919
contexts: {
19201920
let mut contexts = Contexts::new();
19211921
contexts.add(DeviceContext {
1922-
family: "iPhone".to_string().into(),
1923-
model: "iPhone8,4".to_string().into(),
1922+
family: "iPhone".to_owned().into(),
1923+
model: "iPhone8,4".to_owned().into(),
19241924
..Default::default()
19251925
});
19261926
Annotated::new(contexts)
@@ -1948,8 +1948,8 @@ mod tests {
19481948
contexts: {
19491949
let mut contexts = Contexts::new();
19501950
contexts.add(DeviceContext {
1951-
family: "iPhone".to_string().into(),
1952-
model: "iPhone12,8".to_string().into(),
1951+
family: "iPhone".to_owned().into(),
1952+
model: "iPhone12,8".to_owned().into(),
19531953
..Default::default()
19541954
});
19551955
Annotated::new(contexts)
@@ -1977,7 +1977,7 @@ mod tests {
19771977
contexts: {
19781978
let mut contexts = Contexts::new();
19791979
contexts.add(DeviceContext {
1980-
family: "android".to_string().into(),
1980+
family: "android".to_owned().into(),
19811981
processor_frequency: 1000.into(),
19821982
processor_count: 6.into(),
19831983
memory_size: (2 * 1024 * 1024 * 1024).into(),
@@ -2008,7 +2008,7 @@ mod tests {
20082008
contexts: {
20092009
let mut contexts = Contexts::new();
20102010
contexts.add(DeviceContext {
2011-
family: "android".to_string().into(),
2011+
family: "android".to_owned().into(),
20122012
processor_frequency: 2000.into(),
20132013
processor_count: 8.into(),
20142014
memory_size: (6 * 1024 * 1024 * 1024).into(),
@@ -2039,7 +2039,7 @@ mod tests {
20392039
contexts: {
20402040
let mut contexts = Contexts::new();
20412041
contexts.add(DeviceContext {
2042-
family: "android".to_string().into(),
2042+
family: "android".to_owned().into(),
20432043
processor_frequency: 2500.into(),
20442044
processor_count: 8.into(),
20452045
memory_size: (6 * 1024 * 1024 * 1024).into(),
@@ -2416,8 +2416,8 @@ mod tests {
24162416
contexts: {
24172417
let mut contexts = Contexts::new();
24182418
contexts.add(DeviceContext {
2419-
family: "iPhone".to_string().into(),
2420-
model: "iPhone15,3".to_string().into(),
2419+
family: "iPhone".to_owned().into(),
2420+
model: "iPhone15,3".to_owned().into(),
24212421
..Default::default()
24222422
});
24232423
Annotated::new(contexts)
@@ -4236,20 +4236,20 @@ mod tests {
42364236
assert_eq!(user.data, {
42374237
let mut map = Object::new();
42384238
map.insert(
4239-
"other".to_string(),
4239+
"other".to_owned(),
42404240
Annotated::new(Value::String("value".to_owned())),
42414241
);
42424242
Annotated::new(map)
42434243
});
42444244
assert_eq!(user.other, Object::new());
4245-
assert_eq!(user.username, Annotated::new("john".to_string().into()));
4246-
assert_eq!(user.sentry_user, Annotated::new("id:123456".to_string()));
4245+
assert_eq!(user.username, Annotated::new("john".to_owned().into()));
4246+
assert_eq!(user.sentry_user, Annotated::new("id:123456".to_owned()));
42474247
}
42484248

42494249
#[test]
42504250
fn test_handle_types_in_spaced_exception_values() {
42514251
let mut exception = Annotated::new(Exception {
4252-
value: Annotated::new("ValueError: unauthorized".to_string().into()),
4252+
value: Annotated::new("ValueError: unauthorized".to_owned().into()),
42534253
..Exception::default()
42544254
});
42554255
normalize_exception(&mut exception);
@@ -4262,7 +4262,7 @@ mod tests {
42624262
#[test]
42634263
fn test_handle_types_in_non_spaced_excepton_values() {
42644264
let mut exception = Annotated::new(Exception {
4265-
value: Annotated::new("ValueError:unauthorized".to_string().into()),
4265+
value: Annotated::new("ValueError:unauthorized".to_owned().into()),
42664266
..Exception::default()
42674267
});
42684268
normalize_exception(&mut exception);
@@ -4275,8 +4275,8 @@ mod tests {
42754275
#[test]
42764276
fn test_rejects_empty_exception_fields() {
42774277
let mut exception = Annotated::new(Exception {
4278-
value: Annotated::new("".to_string().into()),
4279-
ty: Annotated::new("".to_string()),
4278+
value: Annotated::new("".to_owned().into()),
4279+
ty: Annotated::new("".to_owned()),
42804280
..Default::default()
42814281
});
42824282

relay-event-normalization/src/event_error.rs

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,8 @@ mod tests {
100100
assert_eq!(
101101
*event.value().unwrap().errors.value().unwrap(),
102102
vec![Annotated::from(EventProcessingError {
103-
ty: Annotated::from("invalid_data".to_string()),
104-
name: Annotated::from("event_id".to_string()),
103+
ty: Annotated::from("invalid_data".to_owned()),
104+
name: Annotated::from("event_id".to_owned()),
105105
value: Annotated::empty(),
106106
other: Object::default(),
107107
})]
@@ -114,7 +114,7 @@ mod tests {
114114
other: {
115115
let mut other = Object::new();
116116
other.insert(
117-
"foo".to_string(),
117+
"foo".to_owned(),
118118
Annotated::from_error(ErrorKind::InvalidData, None),
119119
);
120120
other
@@ -132,8 +132,8 @@ mod tests {
132132
assert_eq!(
133133
*event.value().unwrap().errors.value().unwrap(),
134134
vec![Annotated::from(EventProcessingError {
135-
ty: Annotated::from("invalid_data".to_string()),
136-
name: Annotated::from("foo".to_string()),
135+
ty: Annotated::from("invalid_data".to_owned()),
136+
name: Annotated::from("foo".to_owned()),
137137
value: Annotated::empty(),
138138
other: Object::default(),
139139
})]
@@ -160,8 +160,8 @@ mod tests {
160160
assert_eq!(
161161
*event.value().unwrap().errors.value().unwrap(),
162162
vec![Annotated::from(EventProcessingError {
163-
ty: Annotated::from("invalid_data".to_string()),
164-
name: Annotated::from("breadcrumbs.values.0.type".to_string()),
163+
ty: Annotated::from("invalid_data".to_owned()),
164+
name: Annotated::from("breadcrumbs.values.0.type".to_owned()),
165165
value: Annotated::empty(),
166166
other: Object::default(),
167167
})]
@@ -189,14 +189,14 @@ mod tests {
189189
*event.value().unwrap().errors.value().unwrap(),
190190
vec![
191191
Annotated::from(EventProcessingError {
192-
ty: Annotated::from("invalid_data".to_string()),
193-
name: Annotated::from("event_id".to_string()),
192+
ty: Annotated::from("invalid_data".to_owned()),
193+
name: Annotated::from("event_id".to_owned()),
194194
value: Annotated::empty(),
195195
other: Object::default(),
196196
}),
197197
Annotated::from(EventProcessingError {
198-
ty: Annotated::from("missing_attribute".to_string()),
199-
name: Annotated::from("event_id".to_string()),
198+
ty: Annotated::from("missing_attribute".to_owned()),
199+
name: Annotated::from("event_id".to_owned()),
200200
value: Annotated::empty(),
201201
other: Object::default(),
202202
})
@@ -226,14 +226,14 @@ mod tests {
226226
*event.value().unwrap().errors.value().unwrap(),
227227
vec![
228228
Annotated::from(EventProcessingError {
229-
ty: Annotated::from("invalid_data".to_string()),
230-
name: Annotated::from("event_id".to_string()),
229+
ty: Annotated::from("invalid_data".to_owned()),
230+
name: Annotated::from("event_id".to_owned()),
231231
value: Annotated::from(Value::I64(42)),
232232
other: Object::default(),
233233
}),
234234
Annotated::from(EventProcessingError {
235-
ty: Annotated::from("missing_attribute".to_string()),
236-
name: Annotated::from("event_id".to_string()),
235+
ty: Annotated::from("missing_attribute".to_owned()),
236+
name: Annotated::from("event_id".to_owned()),
237237
value: Annotated::empty(),
238238
other: Object::default(),
239239
})

0 commit comments

Comments
 (0)