Skip to content

Commit b3aef37

Browse files
committed
Use a custom capacity for the JSON buffer
1 parent 9c6f56b commit b3aef37

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

src/project.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,12 @@ impl RustAnalyzerProject {
3131

3232
/// Write rust-project.json to disk
3333
pub fn write_to_disk(&self) -> Result<(), std::io::Error> {
34-
std::fs::write(
35-
"./rust-project.json",
36-
serde_json::to_vec(&self).expect("Failed to serialize to JSON"),
37-
)?;
34+
// Using the capacity 2^14 = 16384 since the file length in bytes is higher than 2^13.
35+
// The final length is not known exactly because it depends on the user's sysroot path,
36+
// the current number of exercises etc.
37+
let mut buf = Vec::with_capacity(16384);
38+
serde_json::to_writer(&mut buf, &self).expect("Failed to serialize to JSON");
39+
std::fs::write("rust-project.json", buf)?;
3840
Ok(())
3941
}
4042

0 commit comments

Comments
 (0)