Skip to content

Commit

Permalink
Make .indices 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 30, 2019
1 parent 6297b0e commit 519cfde
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 10 deletions.
14 changes: 12 additions & 2 deletions src/core.c/Cool.pm6
Expand Up @@ -207,8 +207,18 @@ my class Cool { # declared in BOOTSTRAP
self.Str.contains($needle, $pos.Int)
}

method indices(Cool:D: |c) {
self.Str.indices(|c)
proto method indices(|) {*}
multi method indices(Cool:D: Cool:D $needle, :$overlap) {
self.Str.indices: $needle.Str, :$overlap
}
multi method indices(Cool:D: Str:D $needle, :$overlap) {
self.Str.indices: $needle, :$overlap
}
multi method indices(Cool:D: Cool:D $needle, Cool:D $start, :$overlap) {
self.Str.indices: $needle.Str, $start.Int, :$overlap
}
multi method indices(Cool:D: Str:D $needle, Int:D $start, :$overlap) {
self.Str.indices: $needle, $start, :$overlap
}

proto method index(|) {*}
Expand Down
14 changes: 6 additions & 8 deletions src/core.c/Str.pm6
Expand Up @@ -206,10 +206,8 @@ my class Str does Stringy { # declared in BOOTSTRAP
self.contains($needle, $pos.Int)
}

# TODO Use coercer in 1 candidate when RT131014
proto method indices(|) {*}
multi method indices(Str:D: Cool:D $needle, *%pars) {
self.indices: $needle.Str, |%pars
multi method indices(Str:D: Cool:D $needle, :$overlap) {
self.indices: $needle.Str, :$overlap
}
multi method indices(Str:D: Str:D $needle, :$overlap) {
nqp::stmts(
Expand All @@ -225,11 +223,11 @@ my class Str does Stringy { # declared in BOOTSTRAP
($pos = nqp::add_i($i,$add))
)
),
$indices.List
nqp::p6bindattrinvres(nqp::create(List),List,'$!reified',$indices)
)
}
multi method indices(Str:D: Cool:D $needle, Cool:D $start, *%pars) {
self.indices: $needle.Str, $start.Int, |%pars
multi method indices(Str:D: Cool:D $needle, Cool:D $start, :$overlap) {
self.indices: $needle.Str, $start.Int, :$overlap
}
multi method indices(Str:D: Str:D $needle, Int:D $start, :$overlap) {
nqp::stmts(
Expand All @@ -249,7 +247,7 @@ my class Str does Stringy { # declared in BOOTSTRAP
($pos = nqp::add_i($i,$add))
)
),
$indices.List
nqp::p6bindattrinvres(nqp::create(List),List,'$!reified',$indices)
)
)
)
Expand Down

0 comments on commit 519cfde

Please sign in to comment.