Skip to content

Commit 9476e72

Browse files
committed
More borrowing, less copying
1 parent 251c3c3 commit 9476e72

1 file changed

Lines changed: 13 additions & 13 deletions

File tree

native/src/core/su/connect.rs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,21 +12,21 @@ use libc::pollfd as PollFd;
1212
use num_traits::AsPrimitive;
1313
use std::{fmt::Write, fs::File, os::fd::AsRawFd, process::Command, process::exit};
1414

15-
struct Extra {
15+
struct Extra<'a> {
1616
key: &'static str,
17-
value: ExtraVal,
17+
value: ExtraVal<'a>,
1818
}
1919

20-
enum ExtraVal {
20+
enum ExtraVal<'a> {
2121
Int(i32),
2222
Bool(bool),
23-
Str(String),
24-
IntList(Vec<u32>),
23+
Str(&'a str),
24+
IntList(&'a [u32]),
2525
}
2626

27-
impl Extra {
27+
impl Extra<'_> {
2828
fn add_intent(&self, cmd: &mut Command) {
29-
match &self.value {
29+
match self.value {
3030
Int(i) => {
3131
cmd.args(["--ei", self.key, &i.to_string()]);
3232
}
@@ -48,7 +48,7 @@ impl Extra {
4848

4949
fn add_bind(&self, cmd: &mut Command) {
5050
let mut tmp: String;
51-
match &self.value {
51+
match self.value {
5252
Int(i) => {
5353
tmp = format!("{}:i:{}", self.key, i);
5454
}
@@ -71,7 +71,7 @@ impl Extra {
7171
}
7272

7373
fn add_bind_legacy(&self, cmd: &mut Command) {
74-
match &self.value {
74+
match self.value {
7575
Str(s) => {
7676
let tmp = format!("{}:s:{}", self.key, s);
7777
cmd.args(["--extra", &tmp]);
@@ -179,7 +179,7 @@ impl SuAppContext<'_> {
179179
let extras = [
180180
Extra {
181181
key: "fifo",
182-
value: Str(fifo.to_string()),
182+
value: Str(&fifo),
183183
},
184184
Extra {
185185
key: "uid",
@@ -271,15 +271,15 @@ impl SuAppContext<'_> {
271271
},
272272
Extra {
273273
key: "context",
274-
value: Str(self.request.context.clone()),
274+
value: Str(&self.request.context),
275275
},
276276
Extra {
277277
key: "gids",
278-
value: IntList(self.request.gids.clone()),
278+
value: IntList(&self.request.gids),
279279
},
280280
Extra {
281281
key: "command",
282-
value: Str(command.clone()),
282+
value: Str(command),
283283
},
284284
Extra {
285285
key: "notify",

0 commit comments

Comments
 (0)