Skip to content

Commit a7ca69d

Browse files
committed
fix(runtime): panic in with_current directly
Calling to try_with_current introduces overhead.
1 parent 44f9796 commit a7ca69d

File tree

1 file changed

+10
-3
lines changed
  • compio-runtime/src/runtime

1 file changed

+10
-3
lines changed

compio-runtime/src/runtime/mod.rs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,16 @@ impl Runtime {
8080
///
8181
/// This method will panic if there are no running [`Runtime`].
8282
pub fn with_current<T, F: FnOnce(&Self) -> T>(f: F) -> T {
83-
Self::try_with_current(f)
84-
.ok()
85-
.expect("not in a compio runtime")
83+
#[cold]
84+
fn not_in_compio_runtime() -> ! {
85+
panic!("not in a compio runtime")
86+
}
87+
88+
if CURRENT_RUNTIME.is_set() {
89+
CURRENT_RUNTIME.with(f)
90+
} else {
91+
not_in_compio_runtime()
92+
}
8693
}
8794

8895
/// Set this runtime as current runtime, and perform a function in the

0 commit comments

Comments
 (0)