Wrap all non-test uses of in a BufWriter/BufReader for efficiency

This commit is contained in:
Carter Hunt Fogelman 2023-12-26 01:00:02 -08:00 committed by Olivier Goffart
parent d1529af3cc
commit ff27bc79ae
8 changed files with 40 additions and 25 deletions

View file

@ -2,21 +2,25 @@
// SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-Slint-Royalty-free-1.1 OR LicenseRef-Slint-commercial
use anyhow::Context;
use std::io::Write;
use std::io::{BufWriter, Write};
use std::iter::Extend;
use std::path::{Path, PathBuf};
// cSpell: ignore compat constexpr corelib deps sharedvector pathdata
fn enums(path: &Path) -> anyhow::Result<()> {
let mut enums_priv = std::fs::File::create(path.join("slint_enums_internal.h"))
.context("Error creating slint_enums_internal.h file")?;
let mut enums_priv = BufWriter::new(
std::fs::File::create(path.join("slint_enums_internal.h"))
.context("Error creating slint_enums_internal.h file")?,
);
writeln!(enums_priv, "#pragma once")?;
writeln!(enums_priv, "// This file is auto-generated from {}", file!())?;
writeln!(enums_priv, "#include \"slint_enums.h\"")?;
writeln!(enums_priv, "namespace slint::cbindgen_private {{")?;
let mut enums_pub = std::fs::File::create(path.join("slint_enums.h"))
.context("Error creating slint_enums.h file")?;
let mut enums_pub = BufWriter::new(
std::fs::File::create(path.join("slint_enums.h"))
.context("Error creating slint_enums.h file")?,
);
writeln!(enums_pub, "#pragma once")?;
writeln!(enums_pub, "// This file is auto-generated from {}", file!())?;
writeln!(enums_pub, "namespace slint {{")?;
@ -81,14 +85,18 @@ namespace slint::platform::key_codes {{
}
fn builtin_structs(path: &Path) -> anyhow::Result<()> {
let mut structs_pub = std::fs::File::create(path.join("slint_builtin_structs.h"))
.context("Error creating slint_builtin_structs.h file")?;
let mut structs_pub = BufWriter::new(
std::fs::File::create(path.join("slint_builtin_structs.h"))
.context("Error creating slint_builtin_structs.h file")?,
);
writeln!(structs_pub, "#pragma once")?;
writeln!(structs_pub, "// This file is auto-generated from {}", file!())?;
writeln!(structs_pub, "namespace slint {{")?;
let mut structs_priv = std::fs::File::create(path.join("slint_builtin_structs_internal.h"))
.context("Error creating slint_builtin_structs_internal.h file")?;
let mut structs_priv = BufWriter::new(
std::fs::File::create(path.join("slint_builtin_structs_internal.h"))
.context("Error creating slint_builtin_structs_internal.h file")?,
);
writeln!(structs_priv, "#pragma once")?;
writeln!(structs_priv, "// This file is auto-generated from {}", file!())?;
writeln!(structs_priv, "#include \"slint_builtin_structs.h\"")?;