Skip to content

Commit bec7716

Browse files
committed
revert use of tokio::fs (back to std::fs)
there was a noticeable performance increase in the benchmarks Under the hood `tokio::fs` uses more overhead than `std::fs`. And, the usage here are in synchronous contexts anyway.
1 parent 12a5070 commit bec7716

File tree

4 files changed

+13
-10
lines changed

4 files changed

+13
-10
lines changed

cpp-linter/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ reqwest = "0.12.24"
2828
semver = "1.0.27"
2929
serde = { version = "1.0.228", features = ["derive"] }
3030
serde_json = "1.0.145"
31-
tokio = { version = "1.48.0", features = ["macros", "rt-multi-thread", "process", "fs"] }
31+
tokio = { version = "1.48.0", features = ["macros", "rt-multi-thread", "process"] }
3232
tokio-macros = "2.5.0"
3333
tokio-stream = "0.1.17"
3434
which = "8.0.0"

cpp-linter/src/clang_tools/clang_format.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
//! This module holds functionality specific to running clang-format and parsing it's
22
//! output.
33
4-
use std::sync::{Arc, Mutex};
4+
use std::{
5+
fs,
6+
sync::{Arc, Mutex},
7+
};
58

69
use anyhow::{anyhow, Context, Result};
710
use log::Level;
811
use serde::Deserialize;
9-
use tokio::{fs, process::Command};
12+
use tokio::process::Command;
1013

1114
// project-specific crates/modules
1215
use super::MakeSuggestions;
@@ -155,7 +158,7 @@ pub async fn run_clang_format(
155158
};
156159
format_advice.patched = patched;
157160
if !format_advice.replacements.is_empty() {
158-
let original_contents = fs::read(&file_name).await.with_context(|| {
161+
let original_contents = fs::read(&file_name).with_context(|| {
159162
format!(
160163
"Failed to read file's original content before translating byte offsets: {file_name}",
161164
)

cpp-linter/src/clang_tools/clang_tidy.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
44
use std::{
55
env::{consts::OS, current_dir},
6+
fs,
67
path::PathBuf,
78
sync::{Arc, Mutex},
89
};
@@ -11,7 +12,7 @@ use std::{
1112
use anyhow::{anyhow, Context, Result};
1213
use regex::Regex;
1314
use serde::Deserialize;
14-
use tokio::{fs, process::Command};
15+
use tokio::process::Command;
1516

1617
// project-specific modules/crates
1718
use super::MakeSuggestions;
@@ -288,7 +289,7 @@ pub async fn run_clang_tidy(
288289
None
289290
} else {
290291
args.push("--fix-errors".to_string());
291-
Some(fs::read_to_string(&file_name).await.with_context(|| {
292+
Some(fs::read_to_string(&file_name).with_context(|| {
292293
format!(
293294
"Failed to cache file's original content before applying clang-tidy changes: {}",
294295
file_name.clone()
@@ -336,12 +337,10 @@ pub async fn run_clang_tidy(
336337
// cache file changes in a buffer and restore the original contents for further analysis
337338
tidy_advice.patched = Some(
338339
fs::read(&file_name)
339-
.await
340340
.with_context(|| format!("Failed to read changes from clang-tidy: {file_name}"))?,
341341
);
342342
// original_content is guaranteed to be Some() value at this point
343343
fs::write(&file_name, original_content.unwrap())
344-
.await
345344
.with_context(|| format!("Failed to restore file's original content: {file_name}"))?;
346345
}
347346
{

cpp-linter/src/clang_tools/mod.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
use std::{
55
env::current_dir,
66
fmt::{self, Display},
7+
fs,
78
path::{Path, PathBuf},
89
sync::{Arc, Mutex},
910
};
@@ -13,7 +14,7 @@ use anyhow::{anyhow, Context, Result};
1314
use git2::{DiffOptions, Patch};
1415
use regex::Regex;
1516
use semver::Version;
16-
use tokio::{fs, process::Command, task::JoinSet};
17+
use tokio::{process::Command, task::JoinSet};
1718
use which::{which, which_in};
1819

1920
// project-specific modules/crates
@@ -229,7 +230,7 @@ pub async fn capture_clang_tools_output(
229230

230231
// parse database (if provided) to match filenames when parsing clang-tidy's stdout
231232
if let Some(db_path) = &clang_params.database {
232-
if let Ok(db_str) = fs::read(db_path.join("compile_commands.json")).await {
233+
if let Ok(db_str) = fs::read(db_path.join("compile_commands.json")) {
233234
clang_params.database_json = Some(
234235
// A compilation database should be UTF-8 encoded, but file paths are not; use lossy conversion.
235236
serde_json::from_str::<Vec<CompilationUnit>>(&String::from_utf8_lossy(&db_str))

0 commit comments

Comments
 (0)