mirror of
https://github.com/topjohnwu/Magisk.git
synced 2025-08-11 08:17:31 +00:00
More borrowing, less copying
This commit is contained in:
@@ -12,21 +12,21 @@ use libc::pollfd as PollFd;
|
|||||||
use num_traits::AsPrimitive;
|
use num_traits::AsPrimitive;
|
||||||
use std::{fmt::Write, fs::File, os::fd::AsRawFd, process::Command, process::exit};
|
use std::{fmt::Write, fs::File, os::fd::AsRawFd, process::Command, process::exit};
|
||||||
|
|
||||||
struct Extra {
|
struct Extra<'a> {
|
||||||
key: &'static str,
|
key: &'static str,
|
||||||
value: ExtraVal,
|
value: ExtraVal<'a>,
|
||||||
}
|
}
|
||||||
|
|
||||||
enum ExtraVal {
|
enum ExtraVal<'a> {
|
||||||
Int(i32),
|
Int(i32),
|
||||||
Bool(bool),
|
Bool(bool),
|
||||||
Str(String),
|
Str(&'a str),
|
||||||
IntList(Vec<u32>),
|
IntList(&'a [u32]),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Extra {
|
impl Extra<'_> {
|
||||||
fn add_intent(&self, cmd: &mut Command) {
|
fn add_intent(&self, cmd: &mut Command) {
|
||||||
match &self.value {
|
match self.value {
|
||||||
Int(i) => {
|
Int(i) => {
|
||||||
cmd.args(["--ei", self.key, &i.to_string()]);
|
cmd.args(["--ei", self.key, &i.to_string()]);
|
||||||
}
|
}
|
||||||
@@ -48,7 +48,7 @@ impl Extra {
|
|||||||
|
|
||||||
fn add_bind(&self, cmd: &mut Command) {
|
fn add_bind(&self, cmd: &mut Command) {
|
||||||
let mut tmp: String;
|
let mut tmp: String;
|
||||||
match &self.value {
|
match self.value {
|
||||||
Int(i) => {
|
Int(i) => {
|
||||||
tmp = format!("{}:i:{}", self.key, i);
|
tmp = format!("{}:i:{}", self.key, i);
|
||||||
}
|
}
|
||||||
@@ -71,7 +71,7 @@ impl Extra {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn add_bind_legacy(&self, cmd: &mut Command) {
|
fn add_bind_legacy(&self, cmd: &mut Command) {
|
||||||
match &self.value {
|
match self.value {
|
||||||
Str(s) => {
|
Str(s) => {
|
||||||
let tmp = format!("{}:s:{}", self.key, s);
|
let tmp = format!("{}:s:{}", self.key, s);
|
||||||
cmd.args(["--extra", &tmp]);
|
cmd.args(["--extra", &tmp]);
|
||||||
@@ -179,7 +179,7 @@ impl SuAppContext<'_> {
|
|||||||
let extras = [
|
let extras = [
|
||||||
Extra {
|
Extra {
|
||||||
key: "fifo",
|
key: "fifo",
|
||||||
value: Str(fifo.to_string()),
|
value: Str(&fifo),
|
||||||
},
|
},
|
||||||
Extra {
|
Extra {
|
||||||
key: "uid",
|
key: "uid",
|
||||||
@@ -271,15 +271,15 @@ impl SuAppContext<'_> {
|
|||||||
},
|
},
|
||||||
Extra {
|
Extra {
|
||||||
key: "context",
|
key: "context",
|
||||||
value: Str(self.request.context.clone()),
|
value: Str(&self.request.context),
|
||||||
},
|
},
|
||||||
Extra {
|
Extra {
|
||||||
key: "gids",
|
key: "gids",
|
||||||
value: IntList(self.request.gids.clone()),
|
value: IntList(&self.request.gids),
|
||||||
},
|
},
|
||||||
Extra {
|
Extra {
|
||||||
key: "command",
|
key: "command",
|
||||||
value: Str(command.clone()),
|
value: Str(command),
|
||||||
},
|
},
|
||||||
Extra {
|
Extra {
|
||||||
key: "notify",
|
key: "notify",
|
||||||
|
Reference in New Issue
Block a user