0
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2025-03-03 09:31:22 -05:00

chore: set lockfile as having no content changes after write (#24023)

Slight perf regression when updating deno_lockfile in
https://github.com/denoland/deno/pull/23979
This commit is contained in:
David Sherret 2024-05-28 23:40:40 -04:00 committed by GitHub
parent 14a74600de
commit a8923534ed
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 10 additions and 8 deletions

View file

@ -77,7 +77,7 @@ pub fn read_lockfile_at_path(filename: PathBuf) -> Result<Lockfile, AnyError> {
}
pub fn write_lockfile_if_has_changes(
lockfile: &Lockfile,
lockfile: &mut Lockfile,
) -> Result<(), AnyError> {
let Some(bytes) = lockfile.resolve_write_bytes() else {
return Ok(()); // nothing to do
@ -85,5 +85,7 @@ pub fn write_lockfile_if_has_changes(
// do an atomic write to reduce the chance of multiple deno
// processes corrupting the file
atomic_write_file(&lockfile.filename, bytes, cache::CACHE_PERM)
.context("Failed writing lockfile.")
.context("Failed writing lockfile.")?;
lockfile.has_content_changed = false;
Ok(())
}

View file

@ -272,8 +272,8 @@ impl LanguageServer {
// Update the lockfile on the file system with anything new
// found after caching
if let Some(lockfile) = cli_options.maybe_lockfile() {
let lockfile = lockfile.lock();
if let Err(err) = write_lockfile_if_has_changes(&lockfile) {
let mut lockfile = lockfile.lock();
if let Err(err) = write_lockfile_if_has_changes(&mut lockfile) {
lsp_warn!("{:#}", err);
}
}

View file

@ -175,7 +175,7 @@ impl ModuleLoadPreparer {
// write the lockfile if there is one
if let Some(lockfile) = &self.lockfile {
write_lockfile_if_has_changes(&lockfile.lock())?;
write_lockfile_if_has_changes(&mut lockfile.lock())?;
}
drop(_pb_clear_guard);

View file

@ -71,7 +71,7 @@ pub async fn info(flags: Flags, info_flags: InfoFlags) -> Result<(), AnyError> {
// write out the lockfile if there is one
if let Some(lockfile) = &maybe_lockfile {
graph_exit_lock_errors(&graph);
write_lockfile_if_has_changes(&lockfile.lock())?;
write_lockfile_if_has_changes(&mut lockfile.lock())?;
}
if info_flags.json {

View file

@ -267,7 +267,7 @@ async fn install_local(
crate::module_loader::load_top_level_deps(&factory).await?;
if let Some(lockfile) = factory.cli_options().maybe_lockfile() {
write_lockfile_if_has_changes(&lockfile.lock())?;
write_lockfile_if_has_changes(&mut lockfile.lock())?;
}
Ok(())

View file

@ -533,7 +533,7 @@ impl CliMainWorkerFactory {
// For npm binary commands, ensure that the lockfile gets updated
// so that we can re-use the npm resolution the next time it runs
// for better performance
write_lockfile_if_has_changes(&lockfile.lock())?;
write_lockfile_if_has_changes(&mut lockfile.lock())?;
}
(node_resolution.into_url(), is_main_cjs)