Skip to content

Commit 8a25e75

Browse files
eduardosmAmanieu
authored andcommitted
Use str::strip_prefix instead of str::starts_with + manual strip
1 parent a0a2fcf commit 8a25e75

File tree

1 file changed

+37
-38
lines changed

1 file changed

+37
-38
lines changed

crates/stdarch-gen/src/main.rs

Lines changed: 37 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -352,8 +352,8 @@ fn type_to_lane_suffixes<'a>(out_t: &'a str, in_t: &'a str, re_to_out: bool) ->
352352
fn type_to_rot_suffix(c_name: &str, suf: &str) -> String {
353353
let ns: Vec<_> = c_name.split('_').collect();
354354
assert_eq!(ns.len(), 2);
355-
if suf.starts_with("q") {
356-
format!("{}q_{}{}", ns[0], ns[1], &suf[1..])
355+
if let Some(suf) = suf.strip_prefix("q") {
356+
format!("{}q_{}{}", ns[0], ns[1], suf)
357357
} else {
358358
format!("{c_name}{suf}")
359359
}
@@ -3298,18 +3298,18 @@ mod test {
32983298
fn_type = Fntype::Normal;
32993299
separate = false;
33003300
} else if line.starts_with("//") {
3301-
} else if line.starts_with("name = ") {
3302-
current_name = Some(String::from(&line[7..]));
3303-
} else if line.starts_with("fn = ") {
3304-
current_fn = Some(String::from(&line[5..]));
3305-
} else if line.starts_with("multi_fn = ") {
3306-
multi_fn.push(String::from(&line[11..]));
3307-
} else if line.starts_with("constn = ") {
3308-
constn = Some(String::from(&line[9..]));
3309-
} else if line.starts_with("arm = ") {
3310-
current_arm = Some(String::from(&line[6..]));
3311-
} else if line.starts_with("aarch64 = ") {
3312-
current_aarch64 = Some(String::from(&line[10..]));
3301+
} else if let Some(line) = line.strip_prefix("name = ") {
3302+
current_name = Some(String::from(line));
3303+
} else if let Some(line) = line.strip_prefix("fn = ") {
3304+
current_fn = Some(String::from(line));
3305+
} else if let Some(line) = line.strip_prefix("multi_fn = ") {
3306+
multi_fn.push(String::from(line));
3307+
} else if let Some(line) = line.strip_prefix("constn = ") {
3308+
constn = Some(String::from(line));
3309+
} else if let Some(line) = line.strip_prefix("arm = ") {
3310+
current_arm = Some(String::from(line));
3311+
} else if let Some(line) = line.strip_prefix("aarch64 = ") {
3312+
current_aarch64 = Some(String::from(line));
33133313
} else if line.starts_with("double-suffixes") {
33143314
suffix = Double;
33153315
} else if line.starts_with("no-q") {
@@ -3348,35 +3348,35 @@ mod test {
33483348
suffix = Rot;
33493349
} else if line.starts_with("rot-lane-suffixes") {
33503350
suffix = RotLane;
3351-
} else if line.starts_with("a = ") {
3352-
a = line[4..].split(',').map(|v| v.trim().to_string()).collect();
3353-
} else if line.starts_with("b = ") {
3354-
b = line[4..].split(',').map(|v| v.trim().to_string()).collect();
3355-
} else if line.starts_with("c = ") {
3356-
c = line[4..].split(',').map(|v| v.trim().to_string()).collect();
3357-
} else if line.starts_with("n = ") {
3358-
n = Some(String::from(&line[4..]));
3359-
} else if line.starts_with("fixed = ") {
3360-
fixed = line[8..].split(',').map(|v| v.trim().to_string()).collect();
3361-
} else if line.starts_with("validate ") {
3362-
let e = line[9..].split(',').map(|v| v.trim().to_string()).collect();
3351+
} else if let Some(line) = line.strip_prefix("a = ") {
3352+
a = line.split(',').map(|v| v.trim().to_string()).collect();
3353+
} else if let Some(line) = line.strip_prefix("b = ") {
3354+
b = line.split(',').map(|v| v.trim().to_string()).collect();
3355+
} else if let Some(line) = line.strip_prefix("c = ") {
3356+
c = line.split(',').map(|v| v.trim().to_string()).collect();
3357+
} else if let Some(line) = line.strip_prefix("n = ") {
3358+
n = Some(String::from(line));
3359+
} else if let Some(line) = line.strip_prefix("fixed = ") {
3360+
fixed = line.split(',').map(|v| v.trim().to_string()).collect();
3361+
} else if let Some(line) = line.strip_prefix("validate ") {
3362+
let e = line.split(',').map(|v| v.trim().to_string()).collect();
33633363
current_tests.push((a.clone(), b.clone(), c.clone(), n.clone(), e));
3364-
} else if line.starts_with("link-aarch64 = ") {
3365-
link_aarch64 = Some(String::from(&line[15..]));
3366-
} else if line.starts_with("const-aarch64 = ") {
3367-
const_aarch64 = Some(String::from(&line[16..]));
3368-
} else if line.starts_with("link-arm = ") {
3369-
link_arm = Some(String::from(&line[11..]));
3370-
} else if line.starts_with("const-arm = ") {
3371-
const_arm = Some(String::from(&line[12..]));
3364+
} else if let Some(line) = line.strip_prefix("link-aarch64 = ") {
3365+
link_aarch64 = Some(String::from(line));
3366+
} else if let Some(line) = line.strip_prefix("const-aarch64 = ") {
3367+
const_aarch64 = Some(String::from(line));
3368+
} else if let Some(line) = line.strip_prefix("link-arm = ") {
3369+
link_arm = Some(String::from(line));
3370+
} else if let Some(line) = line.strip_prefix("const-arm = ") {
3371+
const_arm = Some(String::from(line));
33723372
} else if line.starts_with("load_fn") {
33733373
fn_type = Fntype::Load;
33743374
} else if line.starts_with("store_fn") {
33753375
fn_type = Fntype::Store;
33763376
} else if line.starts_with("arm-aarch64-separate") {
33773377
separate = true;
3378-
} else if line.starts_with("target = ") {
3379-
target = match Some(String::from(&line[9..])) {
3378+
} else if let Some(line) = line.strip_prefix("target = ") {
3379+
target = match Some(String::from(line)) {
33803380
Some(input) => match input.as_str() {
33813381
"v7" => ArmV7,
33823382
"vfp4" => Vfp4,
@@ -3393,8 +3393,7 @@ mod test {
33933393
},
33943394
_ => Default,
33953395
}
3396-
} else if line.starts_with("generate ") {
3397-
let line = &line[9..];
3396+
} else if let Some(line) = line.strip_prefix("generate ") {
33983397
let types: Vec<String> = line
33993398
.split(',')
34003399
.map(|v| v.trim().to_string())

0 commit comments

Comments
 (0)