Merge "aconfig: remove unnecessary clones" into main

This commit is contained in:
Treehugger Robot
2023-09-11 12:51:17 +00:00
committed by Gerrit Code Review
3 changed files with 13 additions and 13 deletions

View File

@@ -38,9 +38,9 @@ where
let cpp_namespace = package.replace('.', "::"); let cpp_namespace = package.replace('.', "::");
ensure!(codegen::is_valid_name_ident(&header)); ensure!(codegen::is_valid_name_ident(&header));
let context = Context { let context = Context {
header: header.clone(), header: &header,
cpp_namespace, cpp_namespace: &cpp_namespace,
package: package.to_string(), package,
readwrite, readwrite,
for_test: codegen_mode == CodegenMode::Test, for_test: codegen_mode == CodegenMode::Test,
class_elements, class_elements,
@@ -77,10 +77,10 @@ pub struct FileSpec<'a> {
} }
#[derive(Serialize)] #[derive(Serialize)]
pub struct Context { pub struct Context<'a> {
pub header: String, pub header: &'a str,
pub cpp_namespace: String, pub cpp_namespace: &'a str,
pub package: String, pub package: &'a str,
pub readwrite: bool, pub readwrite: bool,
pub for_test: bool, pub for_test: bool,
pub class_elements: Vec<ClassElement>, pub class_elements: Vec<ClassElement>,
@@ -517,7 +517,7 @@ void com_android_aconfig_test_reset_flags() {
for file in generated { for file in generated {
generated_files_map.insert( generated_files_map.insert(
String::from(file.path.to_str().unwrap()), String::from(file.path.to_str().unwrap()),
String::from_utf8(file.contents.clone()).unwrap(), String::from_utf8(file.contents).unwrap(),
); );
} }

View File

@@ -282,7 +282,7 @@ mod tests {
None, None,
crate::test::first_significant_code_diff( crate::test::first_significant_code_diff(
file_set.get(file_path).unwrap(), file_set.get(file_path).unwrap(),
&String::from_utf8(file.contents.clone()).unwrap() &String::from_utf8(file.contents).unwrap()
), ),
"File {} content is not correct", "File {} content is not correct",
file_path file_path
@@ -362,7 +362,7 @@ mod tests {
None, None,
crate::test::first_significant_code_diff( crate::test::first_significant_code_diff(
file_set.get(file_path).unwrap(), file_set.get(file_path).unwrap(),
&String::from_utf8(file.contents.clone()).unwrap() &String::from_utf8(file.contents).unwrap()
), ),
"File {} content is not correct", "File {} content is not correct",
file_path file_path

View File

@@ -137,14 +137,14 @@ fn open_single_file(matches: &ArgMatches, arg_name: &str) -> Result<Input> {
} }
fn write_output_file_realtive_to_dir(root: &Path, output_file: &OutputFile) -> Result<()> { fn write_output_file_realtive_to_dir(root: &Path, output_file: &OutputFile) -> Result<()> {
let path = root.join(output_file.path.clone()); let path = root.join(&output_file.path);
let parent = path let parent = path
.parent() .parent()
.ok_or(anyhow!("unable to locate parent of output file {}", path.display()))?; .ok_or(anyhow!("unable to locate parent of output file {}", path.display()))?;
fs::create_dir_all(parent) fs::create_dir_all(parent)
.with_context(|| format!("failed to create directory {}", parent.display()))?; .with_context(|| format!("failed to create directory {}", parent.display()))?;
let mut file = fs::File::create(path.clone()) let mut file =
.with_context(|| format!("failed to open {}", path.display()))?; fs::File::create(&path).with_context(|| format!("failed to open {}", path.display()))?;
file.write_all(&output_file.contents) file.write_all(&output_file.contents)
.with_context(|| format!("failed to write to {}", path.display()))?; .with_context(|| format!("failed to write to {}", path.display()))?;
Ok(()) Ok(())