Skip to content
Permalink
Browse files

Streamline Duration.new

- make it a multi
- makes Duration.new(Rat) about 4x as fast (most common case, I would say)
- makes Duration.new(Mu) about 20% faster
  • Loading branch information...
lizmat committed Jan 2, 2019
1 parent 92321be commit de933656bdfa9153cc2a8d8cb8f15374ff411209
Showing with 9 additions and 2 deletions.
  1. +9 −2 src/core/Duration.pm6
@@ -2,8 +2,15 @@ my class Duration is Cool does Real {
has Rat $.tai is default(0.0);
# A linear count of seconds.

method new($tai) {
nqp::p6bindattrinvres(nqp::create(Duration),Duration,'$!tai',$tai.Rat.self) # .self blows up Failures
multi method new(Duration: Rat:D \tai --> Duration:D) {
nqp::p6bindattrinvres(nqp::create(Duration),Duration,'$!tai',tai)
}
multi method new(Duration: \value --> Duration:D) {
nqp::if(
nqp::istype((my \tai := value.Rat),Failure),
tai.throw,
nqp::p6bindattrinvres(nqp::create(Duration),Duration,'$!tai',tai)
)
}

method Bridge(Duration:D:) { $!tai.Num }

0 comments on commit de93365

Please sign in to comment.
You can’t perform that action at this time.