Skip to content

Commit

Permalink
Fast-track .ASSIGN-POS for 1,2,3dimmed arrays
Browse files Browse the repository at this point in the history
Makes them about 40x faster than using the generic N-dimmed ASSIGN-POS
  • Loading branch information
lizmat committed Nov 4, 2016
1 parent 5b2bdeb commit 050cf72
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 0 deletions.
23 changes: 23 additions & 0 deletions src/core/Shaped1Array.pm
Expand Up @@ -29,6 +29,29 @@
)
}

multi method ASSIGN-POS(::?CLASS:D: int \one, \value) {
nqp::ifnull(
nqp::atpos(
nqp::getattr(self,List,'$!reified'),
one),
nqp::bindpos(
nqp::getattr(self,List,'$!reified'),
one,
nqp::p6scalarfromdesc(nqp::getattr(self,Array,'$!descriptor')))
) = value
}
multi method ASSIGN-POS(::?CLASS:D: Int:D \one, \value) {
nqp::ifnull(
nqp::atpos(
nqp::getattr(self,List,'$!reified'),
one),
nqp::bindpos(
nqp::getattr(self,List,'$!reified'),
one,
nqp::p6scalarfromdesc(nqp::getattr(self,Array,'$!descriptor')))
) = value
}

multi method STORE(::?CLASS:D: Iterable:D \in) {
nqp::stmts(
(my \list := nqp::getattr(self,List,'$!reified')),
Expand Down
23 changes: 23 additions & 0 deletions src/core/Shaped2Array.pm
Expand Up @@ -28,6 +28,29 @@
one, two, $scalar) }
)
}

multi method ASSIGN-POS(::?CLASS:D: int \one, int \two, \value) {
nqp::ifnull(
nqp::atpos2d(
nqp::getattr(self,List,'$!reified'),
one, two),
nqp::bindpos2d(
nqp::getattr(self,List,'$!reified'),
one, two,
nqp::p6scalarfromdesc(nqp::getattr(self,Array,'$!descriptor')))
) = value
}
multi method ASSIGN-POS(::?CLASS:D: Int:D \one, Int:D \two, \value) {
nqp::ifnull(
nqp::atpos2d(
nqp::getattr(self,List,'$!reified'),
one, two),
nqp::bindpos2d(
nqp::getattr(self,List,'$!reified'),
one, two,
nqp::p6scalarfromdesc(nqp::getattr(self,Array,'$!descriptor')))
) = value
}
}

# vim: ft=perl6 expandtab sw=4
23 changes: 23 additions & 0 deletions src/core/Shaped3Array.pm
Expand Up @@ -28,6 +28,29 @@
one, two, three, $scalar) }
)
}

multi method ASSIGN-POS(::?CLASS:D: int \one, int \two, int \three, \value) {
nqp::ifnull(
nqp::atpos3d(
nqp::getattr(self,List,'$!reified'),
one, two, three),
nqp::bindpos3d(
nqp::getattr(self,List,'$!reified'),
one, two, three,
nqp::p6scalarfromdesc(nqp::getattr(self,Array,'$!descriptor')))
) = value
}
multi method ASSIGN-POS(::?CLASS:D: Int:D \one, Int:D \two, Int:D \three, \value) {
nqp::ifnull(
nqp::atpos3d(
nqp::getattr(self,List,'$!reified'),
one, two, three),
nqp::bindpos3d(
nqp::getattr(self,List,'$!reified'),
one, two, three,
nqp::p6scalarfromdesc(nqp::getattr(self,Array,'$!descriptor')))
) = value
}
}

# vim: ft=perl6 expandtab sw=4

0 comments on commit 050cf72

Please sign in to comment.