Skip to content

Commit

Permalink
Make .comb quite a bit faster
Browse files Browse the repository at this point in the history
Especially the Cool variants.  Mostly by making them share the same
proto and getting rid of the |c signature.
  • Loading branch information
lizmat committed Sep 28, 2019
1 parent 3697325 commit 6297b0e
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 5 deletions.
30 changes: 29 additions & 1 deletion src/core.c/Cool.pm6
Expand Up @@ -270,7 +270,35 @@ my class Cool { # declared in BOOTSTRAP
self.Stringy.match(|c)
}

method comb(|c) { self.Str.comb(|c) }
proto method comb(|) {*}
multi method comb(Cool:D: --> Seq:D) {
self.Str.comb
}
multi method comb(Cool:D: Cool:D $size, $limit = * --> Seq:D) {
self.Str.comb($size.Int, $limit)
}
multi method comb(Cool:D: Int:D $size, $limit = * --> Seq:D) {
self.Str.comb($size, $limit)
}
multi method comb(Cool:D: Cool:D $pat --> Seq:D) {
self.Str.comb($pat.Str)
}
multi method comb(Cool:D: Str:D $pat --> Seq:D) {
self.Str.comb($pat)
}
multi method comb(Cool:D: Cool:D $pat, $limit --> Seq:D) {
self.Str.comb($pat.Str, $limit)
}
multi method comb(Cool:D: Str:D $pat, $limit --> Seq:D) {
self.Str.comb($pat, $limit)
}
multi method comb(Cool:D: Regex:D $pattern, :$match --> Seq:D) {
self.Str.comb($pattern, :$match)
}
multi method comb(Cool:D: Regex:D $pattern, $limit, :$match --> Seq:D) {
self.Str.comb($pattern, $limit, :$match)
}

method lines(Cool:D: |c) { self.Str.lines(|c) }
method words(Cool:D: |c) { self.Str.words(|c) }

Expand Down
6 changes: 2 additions & 4 deletions src/core.c/Str.pm6
Expand Up @@ -379,8 +379,6 @@ my class Str does Stringy { # declared in BOOTSTRAP
'"' ~ Rakudo::Internals.PERLIFY-STR(self) ~ '"'
}

proto method comb(|) {*}

my class CombAll does PredictiveIterator {
has str $!str;
has int $!chars;
Expand Down Expand Up @@ -502,7 +500,7 @@ my class Str does Stringy { # declared in BOOTSTRAP
}
}
}
multi method comb(Str:D: Str $pat --> Seq:D) {
multi method comb(Str:D: Str:D $pat --> Seq:D) {
$pat
?? Seq.new(CombPat.new(self,$pat))
!! self.comb
Expand Down Expand Up @@ -534,7 +532,7 @@ my class Str does Stringy { # declared in BOOTSTRAP
}
}
}
multi method comb(Str:D: Str $pat, $limit --> Seq:D) {
multi method comb(Str:D: Str:D $pat, $limit --> Seq:D) {
nqp::istype($limit,Whatever) || $limit == Inf
?? self.comb($pat)
!! $pat
Expand Down

0 comments on commit 6297b0e

Please sign in to comment.