Skip to content

Commit

Permalink
Make init_locking return a reference to the initialized data
Browse files Browse the repository at this point in the history
  • Loading branch information
spastorino committed Oct 30, 2019
1 parent a6ac22e commit 12273cb
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
14 changes: 8 additions & 6 deletions src/librustc_data_structures/sync.rs
Expand Up @@ -497,13 +497,15 @@ impl<T> Once<T> {
/// If the value was already initialized the closure is not called and `false` is returned,
/// otherwise if the value from the closure initializes the inner value, `true` is returned
#[inline]
pub fn init_locking<F: FnOnce() -> T>(&self, f: F) -> bool {
let mut lock = self.0.lock();
if lock.is_some() {
return false;
pub fn init_locking<F: FnOnce() -> T>(&self, f: F) -> &T {
{
let mut lock = self.0.lock();
if lock.is_none() {
*lock = Some(f());
}
}
*lock = Some(f());
true

self.borrow()
}

/// Tries to initialize the inner value by calling the closure without ensuring that no-one
Expand Down
4 changes: 1 addition & 3 deletions src/librustc_metadata/decoder.rs
Expand Up @@ -1351,9 +1351,7 @@ impl<'a, 'tcx> CrateMetadata {
translated_source_file: local_version,
}
}).collect()
});

self.source_map_import_info.borrow()
})
}

/// Get the `DepNodeIndex` corresponding this crate. The result of this
Expand Down

0 comments on commit 12273cb

Please sign in to comment.