Skip to content

Commit 32fecaa

Browse files
committed
Use &'static str instead of String for target features.
It's a more precise type -- these are static values. Also it avoids unnecessary allocations.
1 parent f29f2c8 commit 32fecaa

File tree

3 files changed

+39
-39
lines changed

3 files changed

+39
-39
lines changed

crates/nvvm/src/lib.rs

Lines changed: 34 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,7 @@ pub enum NvvmArch {
339339

340340
impl Display for NvvmArch {
341341
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
342-
f.write_str(&self.target_feature())
342+
f.write_str(self.target_feature())
343343
}
344344
}
345345

@@ -435,40 +435,40 @@ impl NvvmArch {
435435
}
436436

437437
/// Get the target feature string (e.g., "compute_35" for Compute35, "compute_90a" for Compute90a)
438-
pub fn target_feature(&self) -> String {
438+
pub fn target_feature(&self) -> &'static str {
439439
match self {
440-
Self::Compute35 => "compute_35".to_string(),
441-
Self::Compute37 => "compute_37".to_string(),
442-
Self::Compute50 => "compute_50".to_string(),
443-
Self::Compute52 => "compute_52".to_string(),
444-
Self::Compute53 => "compute_53".to_string(),
445-
Self::Compute60 => "compute_60".to_string(),
446-
Self::Compute61 => "compute_61".to_string(),
447-
Self::Compute62 => "compute_62".to_string(),
448-
Self::Compute70 => "compute_70".to_string(),
449-
Self::Compute72 => "compute_72".to_string(),
450-
Self::Compute75 => "compute_75".to_string(),
451-
Self::Compute80 => "compute_80".to_string(),
452-
Self::Compute86 => "compute_86".to_string(),
453-
Self::Compute87 => "compute_87".to_string(),
454-
Self::Compute89 => "compute_89".to_string(),
455-
Self::Compute90 => "compute_90".to_string(),
456-
Self::Compute90a => "compute_90a".to_string(),
457-
Self::Compute100 => "compute_100".to_string(),
458-
Self::Compute100f => "compute_100f".to_string(),
459-
Self::Compute100a => "compute_100a".to_string(),
460-
Self::Compute101 => "compute_101".to_string(),
461-
Self::Compute101f => "compute_101f".to_string(),
462-
Self::Compute101a => "compute_101a".to_string(),
463-
Self::Compute103 => "compute_103".to_string(),
464-
Self::Compute103f => "compute_103f".to_string(),
465-
Self::Compute103a => "compute_103a".to_string(),
466-
Self::Compute120 => "compute_120".to_string(),
467-
Self::Compute120f => "compute_120f".to_string(),
468-
Self::Compute120a => "compute_120a".to_string(),
469-
Self::Compute121 => "compute_121".to_string(),
470-
Self::Compute121f => "compute_121f".to_string(),
471-
Self::Compute121a => "compute_121a".to_string(),
440+
Self::Compute35 => "compute_35",
441+
Self::Compute37 => "compute_37",
442+
Self::Compute50 => "compute_50",
443+
Self::Compute52 => "compute_52",
444+
Self::Compute53 => "compute_53",
445+
Self::Compute60 => "compute_60",
446+
Self::Compute61 => "compute_61",
447+
Self::Compute62 => "compute_62",
448+
Self::Compute70 => "compute_70",
449+
Self::Compute72 => "compute_72",
450+
Self::Compute75 => "compute_75",
451+
Self::Compute80 => "compute_80",
452+
Self::Compute86 => "compute_86",
453+
Self::Compute87 => "compute_87",
454+
Self::Compute89 => "compute_89",
455+
Self::Compute90 => "compute_90",
456+
Self::Compute90a => "compute_90a",
457+
Self::Compute100 => "compute_100",
458+
Self::Compute100f => "compute_100f",
459+
Self::Compute100a => "compute_100a",
460+
Self::Compute101 => "compute_101",
461+
Self::Compute101f => "compute_101f",
462+
Self::Compute101a => "compute_101a",
463+
Self::Compute103 => "compute_103",
464+
Self::Compute103f => "compute_103f",
465+
Self::Compute103a => "compute_103a",
466+
Self::Compute120 => "compute_120",
467+
Self::Compute120f => "compute_120f",
468+
Self::Compute120a => "compute_120a",
469+
Self::Compute121 => "compute_121",
470+
Self::Compute121f => "compute_121f",
471+
Self::Compute121a => "compute_121a",
472472
}
473473
}
474474

crates/rustc_codegen_nvvm/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ impl CodegenBackend for NvvmCodegenBackend {
149149
features.extend(
150150
arch.all_target_features()
151151
.into_iter()
152-
.map(|feature| feature.target_feature()),
152+
.map(|s| s.target_feature().to_string()),
153153
);
154154
break;
155155
}
@@ -238,7 +238,7 @@ impl CodegenBackend for NvvmCodegenBackend {
238238
target_features.extend(
239239
backend_features
240240
.iter()
241-
.map(|f| rustc_span::Symbol::intern(&f.target_feature())),
241+
.map(|f| rustc_span::Symbol::intern(f.target_feature())),
242242
);
243243
break;
244244
}

tests/compiletests/src/main.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ impl Runner {
149149
// which offer `// only-S` and `// ignore-S` for any stage ID `S`.
150150
let stage_id = if variation.name == "default" {
151151
// Use the architecture name as the stage ID.
152-
arch.clone()
152+
arch.to_string()
153153
} else {
154154
// Include the variation name in the stage ID.
155155
format!("{}-{}", arch, variation.name)
@@ -161,7 +161,7 @@ impl Runner {
161161
&self.deps_target_dir,
162162
&self.codegen_backend_path,
163163
CUDA_TARGET,
164-
&arch,
164+
arch,
165165
);
166166
let mut flags = test_rustc_flags(
167167
&self.codegen_backend_path,
@@ -174,7 +174,7 @@ impl Runner {
174174
.deps_target_dir
175175
.join(DepKind::ProcMacro.target_dir_suffix(CUDA_TARGET)),
176176
],
177-
&arch,
177+
arch,
178178
);
179179
flags += variation.extra_flags;
180180

0 commit comments

Comments
 (0)