Skip to content

Commit

Permalink
📝 unlikely is_done
Browse files Browse the repository at this point in the history
  • Loading branch information
Xudong-Huang committed Jul 22, 2024
1 parent 32717ca commit d42cd28
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions src/gen_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,24 @@ use std::thread;
// windows has a minimal size as 0x4a8!!!!
pub const DEFAULT_STACK_SIZE: usize = 0x1000;

#[inline]
#[cold]
fn cold() {}

// #[inline]
// fn likely(b: bool) -> bool {
// if !b { cold() }
// b
// }

#[inline]
fn unlikely(b: bool) -> bool {
if b {
cold()
}
b
}

/// the generator obj type, the functor passed to it must be Send
pub struct GeneratorObj<'a, A, T, const LOCAL: bool> {
gen: StackBox<GeneratorImpl<'a, A, T>>,
Expand Down Expand Up @@ -418,7 +436,7 @@ impl<'a, A, T> GeneratorImpl<'a, A, T> {
/// you should call `set_para` before this method
#[inline]
fn resume(&mut self) -> Option<T> {
if self.is_done() {
if unlikely(self.is_done()) {
return None;
}

Expand All @@ -433,7 +451,7 @@ impl<'a, A, T> GeneratorImpl<'a, A, T> {
/// `raw_send`
#[inline]
fn raw_send(&mut self, para: Option<A>) -> Option<T> {
if self.is_done() {
if unlikely(self.is_done()) {
return None;
}

Expand Down

0 comments on commit d42cd28

Please sign in to comment.