summaryrefslogtreecommitdiffstats
path: root/vendor/addr2line/src/lazy.rs
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:19:50 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:19:50 +0000
commit2e00214b3efbdfeefaa0fe9e8b8fd519de7adc35 (patch)
treed325add32978dbdc1db975a438b3a77d571b1ab8 /vendor/addr2line/src/lazy.rs
parentReleasing progress-linux version 1.68.2+dfsg1-1~progress7.99u1. (diff)
downloadrustc-2e00214b3efbdfeefaa0fe9e8b8fd519de7adc35.tar.xz
rustc-2e00214b3efbdfeefaa0fe9e8b8fd519de7adc35.zip
Merging upstream version 1.69.0+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'vendor/addr2line/src/lazy.rs')
-rw-r--r--vendor/addr2line/src/lazy.rs24
1 files changed, 11 insertions, 13 deletions
diff --git a/vendor/addr2line/src/lazy.rs b/vendor/addr2line/src/lazy.rs
index 280c76b46..a34ed176a 100644
--- a/vendor/addr2line/src/lazy.rs
+++ b/vendor/addr2line/src/lazy.rs
@@ -11,19 +11,17 @@ impl<T> LazyCell<T> {
}
pub fn borrow_with(&self, closure: impl FnOnce() -> T) -> &T {
- unsafe {
- // First check if we're already initialized...
- let ptr = self.contents.get();
- if let Some(val) = &*ptr {
- return val;
- }
- // Note that while we're executing `closure` our `borrow_with` may
- // be called recursively. This means we need to check again after
- // the closure has executed. For that we use the `get_or_insert`
- // method which will only perform mutation if we aren't already
- // `Some`.
- let val = closure();
- (*ptr).get_or_insert(val)
+ // First check if we're already initialized...
+ let ptr = self.contents.get();
+ if let Some(val) = unsafe { &*ptr } {
+ return val;
}
+ // Note that while we're executing `closure` our `borrow_with` may
+ // be called recursively. This means we need to check again after
+ // the closure has executed. For that we use the `get_or_insert`
+ // method which will only perform mutation if we aren't already
+ // `Some`.
+ let val = closure();
+ unsafe { (*ptr).get_or_insert(val) }
}
}