From 8d1fc75b6bbb9aa7aac4d38978bee9be913b28d4 Mon Sep 17 00:00:00 2001 From: bjorn3 Date: Mon, 3 Jan 2022 19:47:33 +0100 Subject: [PATCH] Make MachBackend::triple return &Triple This avoids an unnecessary clone --- cranelift/codegen/src/isa/aarch64/mod.rs | 4 ++-- cranelift/codegen/src/isa/arm32/mod.rs | 4 ++-- cranelift/codegen/src/isa/s390x/mod.rs | 4 ++-- cranelift/codegen/src/isa/x64/mod.rs | 4 ++-- cranelift/codegen/src/machinst/adapter.rs | 5 +---- cranelift/codegen/src/machinst/mod.rs | 2 +- 6 files changed, 10 insertions(+), 13 deletions(-) diff --git a/cranelift/codegen/src/isa/aarch64/mod.rs b/cranelift/codegen/src/isa/aarch64/mod.rs index 183fe1c776..06302d820d 100644 --- a/cranelift/codegen/src/isa/aarch64/mod.rs +++ b/cranelift/codegen/src/isa/aarch64/mod.rs @@ -98,8 +98,8 @@ impl MachBackend for AArch64Backend { "aarch64" } - fn triple(&self) -> Triple { - self.triple.clone() + fn triple(&self) -> &Triple { + &self.triple } fn flags(&self) -> &shared_settings::Flags { diff --git a/cranelift/codegen/src/isa/arm32/mod.rs b/cranelift/codegen/src/isa/arm32/mod.rs index 959be2196b..f80f0d1d5c 100644 --- a/cranelift/codegen/src/isa/arm32/mod.rs +++ b/cranelift/codegen/src/isa/arm32/mod.rs @@ -88,8 +88,8 @@ impl MachBackend for Arm32Backend { "arm32" } - fn triple(&self) -> Triple { - self.triple.clone() + fn triple(&self) -> &Triple { + &self.triple } fn flags(&self) -> &settings::Flags { diff --git a/cranelift/codegen/src/isa/s390x/mod.rs b/cranelift/codegen/src/isa/s390x/mod.rs index 2dd3e9f0b1..3c888a537a 100644 --- a/cranelift/codegen/src/isa/s390x/mod.rs +++ b/cranelift/codegen/src/isa/s390x/mod.rs @@ -101,8 +101,8 @@ impl MachBackend for S390xBackend { "s390x" } - fn triple(&self) -> Triple { - self.triple.clone() + fn triple(&self) -> &Triple { + &self.triple } fn flags(&self) -> &shared_settings::Flags { diff --git a/cranelift/codegen/src/isa/x64/mod.rs b/cranelift/codegen/src/isa/x64/mod.rs index 47677cc885..bb0b1a5352 100644 --- a/cranelift/codegen/src/isa/x64/mod.rs +++ b/cranelift/codegen/src/isa/x64/mod.rs @@ -98,8 +98,8 @@ impl MachBackend for X64Backend { "x64" } - fn triple(&self) -> Triple { - self.triple.clone() + fn triple(&self) -> &Triple { + &self.triple } fn reg_universe(&self) -> &RealRegUniverse { diff --git a/cranelift/codegen/src/machinst/adapter.rs b/cranelift/codegen/src/machinst/adapter.rs index c6c6c0a02f..c3f0bc9d97 100644 --- a/cranelift/codegen/src/machinst/adapter.rs +++ b/cranelift/codegen/src/machinst/adapter.rs @@ -14,16 +14,13 @@ use target_lexicon::Triple; /// A wrapper around a `MachBackend` that provides a `TargetIsa` impl. pub struct TargetIsaAdapter { backend: Box, - triple: Triple, } impl TargetIsaAdapter { /// Create a new `TargetIsa` wrapper around a `MachBackend`. pub fn new(backend: B) -> TargetIsaAdapter { - let triple = backend.triple(); TargetIsaAdapter { backend: Box::new(backend), - triple, } } } @@ -44,7 +41,7 @@ impl TargetIsa for TargetIsaAdapter { } fn triple(&self) -> &Triple { - &self.triple + self.backend.triple() } fn flags(&self) -> &Flags { diff --git a/cranelift/codegen/src/machinst/mod.rs b/cranelift/codegen/src/machinst/mod.rs index 725ab7a0e4..7ea2eb6f7b 100644 --- a/cranelift/codegen/src/machinst/mod.rs +++ b/cranelift/codegen/src/machinst/mod.rs @@ -390,7 +390,7 @@ pub trait MachBackend { fn isa_flags(&self) -> Vec; /// Return triple for this backend. - fn triple(&self) -> Triple; + fn triple(&self) -> &Triple; /// Return name for this backend. fn name(&self) -> &'static str;