Skip to content

Commit

Permalink
Failure handling of Array.pop/shift in private method
Browse files Browse the repository at this point in the history
To reduce the footprint of Array.pop/shift themselves, to make them
more likely targets for inlining.
  • Loading branch information
lizmat committed Apr 1, 2020
1 parent 9b735b7 commit 6793713
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/core.c/Array.pm6
Expand Up @@ -839,15 +839,23 @@ my class Array { # declared in BOOTSTRAP
)
}

# helper subs to reduce size of pop / shift
method !lazy($action) is hidden-from-backtrace {
Failure.new(X::Cannot::Lazy.new(:$action))
}
method !empty($action) is hidden-from-backtrace {
Failure.new(X::Cannot::Empty.new(:$action,:what(self.^name)))
}

method pop(Array:D:) is raw is nodal {
nqp::if(
self.is-lazy,
Failure.new(X::Cannot::Lazy.new(action => 'pop from')),
self!lazy('pop from'),
nqp::if(
nqp::isconcrete(nqp::getattr(self,List,'$!reified'))
&& nqp::elems(nqp::getattr(self,List,'$!reified')),
nqp::pop(nqp::getattr(self,List,'$!reified')),
Failure.new(X::Cannot::Empty.new(:action<pop>,:what(self.^name)))
self!empty('pop')
)
)
}
Expand All @@ -864,7 +872,7 @@ my class Array { # declared in BOOTSTRAP
nqp::isconcrete(nqp::getattr(self,List,'$!todo'))
&& nqp::getattr(self,List,'$!todo').reify-at-least(1),
nqp::shift(nqp::getattr(self,List,'$!reified')),
Failure.new(X::Cannot::Empty.new(:action<shift>,:what(self.^name)))
self!empty('shift')
)
)
}
Expand Down

0 comments on commit 6793713

Please sign in to comment.