<commit_before># all sub postcircumfix [;] candidates here please
proto sub postcircumfix:<[; ]>(|) is nodal { * }

sub MD-ARRAY-SLICE-ONE-POSITION(\SELF, \indices, \idx, int $dim, \target) is raw {
    my int $next-dim = $dim + 1;
    if $next-dim < indices.elems {
        if nqp::istype(idx, Iterable) && !nqp::iscont(idx) {
            for idx {
                MD-ARRAY-SLICE-ONE-POSITION(SELF, indices, $_, $dim, target)
            }
        }
        elsif nqp::istype(idx, Int) {
            MD-ARRAY-SLICE-ONE-POSITION(SELF.AT-POS(idx), indices, indices.AT-POS($next-dim), $next-dim, target)
        }
        elsif nqp::istype(idx, Whatever) {
            for ^SELF.cache.elems {
                MD-ARRAY-SLICE-ONE-POSITION(SELF.AT-POS($_), indices, indices.AT-POS($next-dim), $next-dim, target)
            }
        }
        elsif nqp::istype(idx, Callable) {
            MD-ARRAY-SLICE-ONE-POSITION(SELF, indices, idx.(|(SELF.cache.elems xx (idx.count == Inf ?? 1 !! idx.count))), $dim, target);
        }
        else  {
            MD-ARRAY-SLICE-ONE-POSITION(SELF.AT-POS(idx.Int), indices, indices.AT-POS($next-dim), $next-dim, target)
        }
    }
    else {
        if nqp::istype(idx, Iterable) && !nqp::iscont(idx) {
            for idx {
                MD-ARRAY-SLICE-ONE-POSITION(SELF, indices, $_, $dim, target)
            }
        }
        elsif nqp::istype(idx, Int) {
            nqp::push(target, SELF.AT-POS(idx))
        }
        elsif nqp::istype(idx, Whatever) {
            for ^SELF.cache.elems {
                nqp::push(target, SELF.AT-POS($_))
            }
        }
        elsif nqp::istype(idx, Callable) {
            nqp::push(target, SELF.AT-POS(idx.(|(SELF.cache.elems xx (idx.count == Inf ?? 1 !! idx.count)))))
        }
        else {
            nqp::push(target, SELF.AT-POS(idx.Int))
        }
    }
}
sub MD-ARRAY-SLICE(\SELF, @indices) is raw {
    my \target = IterationBuffer.new;
    MD-ARRAY-SLICE-ONE-POSITION(SELF, @indices, @indices.AT-POS(0), 0, target);
    nqp::p6bindattrinvres(nqp::create(List), List, '$!reified', target)
}

multi sub postcircumfix:<[; ]>(\SELF, @indices) is raw {
    nqp::stmts(
      (my int $elems = @indices.elems),   # reifies
      (my $indices := nqp::getattr(@indices,List,'$!reified')),
      (my int $i = -1),
      nqp::while(
        nqp::islt_i(($i = nqp::add_i($i,1)),$elems)
          && nqp::istype(nqp::atpos($indices,$i),Int),
        nqp::null
      ),
      nqp::if(
        nqp::islt_i($i,$elems),
        MD-ARRAY-SLICE(SELF,@indices),
        nqp::if(
          nqp::iseq_i($elems,2),
          SELF.AT-POS(
            nqp::atpos($indices,0),
            nqp::atpos($indices,1)
          ),
          nqp::if(
            nqp::iseq_i($elems,3),
            SELF.AT-POS(
              nqp::atpos($indices,0),
              nqp::atpos($indices,1),
              nqp::atpos($indices,2)
            ),
            SELF.AT-POS(|@indices)
          )
        )
      )
    )
}

multi sub postcircumfix:<[; ]>(\SELF, @indices, Mu \assignee) is raw {
    nqp::stmts(
      (my int $elems = @indices.elems),   # reifies
      (my $indices := nqp::getattr(@indices,List,'$!reified')),
      (my int $i = -1),
      nqp::while(
        nqp::islt_i(($i = nqp::add_i($i,1)),$elems)
          && nqp::istype(nqp::atpos($indices,$i),Int),
        nqp::null
      ),
      nqp::if(
        nqp::islt_i($i,$elems),
        (MD-ARRAY-SLICE(SELF,@indices) = assignee),
        nqp::if(
          nqp::iseq_i($elems,2),
          SELF.ASSIGN-POS(
            nqp::atpos($indices,0),
            nqp::atpos($indices,1),
            assignee
          ),
          nqp::if(
            nqp::iseq_i($elems,3),
            SELF.ASSIGN-POS(
              nqp::atpos($indices,0),
              nqp::atpos($indices,1),
              nqp::atpos($indices,2),
              assignee
            ),
            SELF.ASSIGN-POS(|@indices,assignee)
          )
        )
      )
    )
}

multi sub postcircumfix:<[; ]>(\SELF, @indices, :$exists!) is raw {
    if $exists {
        my int $elems = @indices.elems;
        my $indices := nqp::getattr(@indices,List,'$!reified');
        my int $i = -1;
        fail X::NYI.new(feature => ':exists on multi-dimensional slices')
          unless nqp::istype(nqp::atpos($indices,$i), Int)
          while nqp::islt_i(++$i,$elems);

        SELF.EXISTS-POS(|@indices)
    }
    else {
        SELF[@indices]
    }
}

multi sub postcircumfix:<[; ]>(\SELF, @indices, :$delete!) is raw {
    if $delete {
        my int $elems = @indices.elems;
        my $indices := nqp::getattr(@indices,List,'$!reified');
        my int $i = -1;
        fail X::NYI.new(feature => ':delete on multi-dimensional slices')
          unless nqp::istype(nqp::atpos($indices,$i), Int)
          while nqp::islt_i(++$i,$elems);

        SELF.DELETE-POS(|@indices)
    }
    else {
        SELF[@indices]
    }
}

multi sub postcircumfix:<[; ]>(\SELF, @indices, :$BIND!) is raw {
    my int $elems = @indices.elems;
    my $indices := nqp::getattr(@indices,List,'$!reified');
    my int $i = -1;
    X::Bind::Slice.new(type => SELF.WHAT).throw
      unless nqp::istype(nqp::atpos($indices,$i), Int)
      while nqp::islt_i(++$i,$elems);

    SELF.BIND-POS(|@indices, $BIND)
}

# vim: ft=perl6 expandtab sw=4
<commit_msg>Make [;]:exists 7x faster for 2/3 dimmed arrays<commit_after># all sub postcircumfix [;] candidates here please
proto sub postcircumfix:<[; ]>(|) is nodal { * }

sub MD-ARRAY-SLICE-ONE-POSITION(\SELF, \indices, \idx, int $dim, \target) is raw {
    my int $next-dim = $dim + 1;
    if $next-dim < indices.elems {
        if nqp::istype(idx, Iterable) && !nqp::iscont(idx) {
            for idx {
                MD-ARRAY-SLICE-ONE-POSITION(SELF, indices, $_, $dim, target)
            }
        }
        elsif nqp::istype(idx, Int) {
            MD-ARRAY-SLICE-ONE-POSITION(SELF.AT-POS(idx), indices, indices.AT-POS($next-dim), $next-dim, target)
        }
        elsif nqp::istype(idx, Whatever) {
            for ^SELF.cache.elems {
                MD-ARRAY-SLICE-ONE-POSITION(SELF.AT-POS($_), indices, indices.AT-POS($next-dim), $next-dim, target)
            }
        }
        elsif nqp::istype(idx, Callable) {
            MD-ARRAY-SLICE-ONE-POSITION(SELF, indices, idx.(|(SELF.cache.elems xx (idx.count == Inf ?? 1 !! idx.count))), $dim, target);
        }
        else  {
            MD-ARRAY-SLICE-ONE-POSITION(SELF.AT-POS(idx.Int), indices, indices.AT-POS($next-dim), $next-dim, target)
        }
    }
    else {
        if nqp::istype(idx, Iterable) && !nqp::iscont(idx) {
            for idx {
                MD-ARRAY-SLICE-ONE-POSITION(SELF, indices, $_, $dim, target)
            }
        }
        elsif nqp::istype(idx, Int) {
            nqp::push(target, SELF.AT-POS(idx))
        }
        elsif nqp::istype(idx, Whatever) {
            for ^SELF.cache.elems {
                nqp::push(target, SELF.AT-POS($_))
            }
        }
        elsif nqp::istype(idx, Callable) {
            nqp::push(target, SELF.AT-POS(idx.(|(SELF.cache.elems xx (idx.count == Inf ?? 1 !! idx.count)))))
        }
        else {
            nqp::push(target, SELF.AT-POS(idx.Int))
        }
    }
}
sub MD-ARRAY-SLICE(\SELF, @indices) is raw {
    my \target = IterationBuffer.new;
    MD-ARRAY-SLICE-ONE-POSITION(SELF, @indices, @indices.AT-POS(0), 0, target);
    nqp::p6bindattrinvres(nqp::create(List), List, '$!reified', target)
}

multi sub postcircumfix:<[; ]>(\SELF, @indices) is raw {
    nqp::stmts(
      (my int $elems = @indices.elems),   # reifies
      (my $indices := nqp::getattr(@indices,List,'$!reified')),
      (my int $i = -1),
      nqp::while(
        nqp::islt_i(($i = nqp::add_i($i,1)),$elems)
          && nqp::istype(nqp::atpos($indices,$i),Int),
        nqp::null
      ),
      nqp::if(
        nqp::islt_i($i,$elems),
        MD-ARRAY-SLICE(SELF,@indices),
        nqp::if(
          nqp::iseq_i($elems,2),
          SELF.AT-POS(
            nqp::atpos($indices,0),
            nqp::atpos($indices,1)
          ),
          nqp::if(
            nqp::iseq_i($elems,3),
            SELF.AT-POS(
              nqp::atpos($indices,0),
              nqp::atpos($indices,1),
              nqp::atpos($indices,2)
            ),
            SELF.AT-POS(|@indices)
          )
        )
      )
    )
}

multi sub postcircumfix:<[; ]>(\SELF, @indices, Mu \assignee) is raw {
    nqp::stmts(
      (my int $elems = @indices.elems),   # reifies
      (my $indices := nqp::getattr(@indices,List,'$!reified')),
      (my int $i = -1),
      nqp::while(
        nqp::islt_i(($i = nqp::add_i($i,1)),$elems)
          && nqp::istype(nqp::atpos($indices,$i),Int),
        nqp::null
      ),
      nqp::if(
        nqp::islt_i($i,$elems),
        (MD-ARRAY-SLICE(SELF,@indices) = assignee),
        nqp::if(
          nqp::iseq_i($elems,2),
          SELF.ASSIGN-POS(
            nqp::atpos($indices,0),
            nqp::atpos($indices,1),
            assignee
          ),
          nqp::if(
            nqp::iseq_i($elems,3),
            SELF.ASSIGN-POS(
              nqp::atpos($indices,0),
              nqp::atpos($indices,1),
              nqp::atpos($indices,2),
              assignee
            ),
            SELF.ASSIGN-POS(|@indices,assignee)
          )
        )
      )
    )
}

multi sub postcircumfix:<[; ]>(\SELF, @indices, :$exists!) is raw {
    nqp::if(
      $exists,
      nqp::stmts(
        (my int $elems = @indices.elems),   # reifies
        (my $indices := nqp::getattr(@indices,List,'$!reified')),
        (my int $i = -1),
        nqp::while(
          nqp::islt_i(($i = nqp::add_i($i,1)),$elems)
            && nqp::istype(nqp::atpos($indices,$i),Int),
          nqp::null
        ),
        nqp::if(
          nqp::islt_i($i,$elems),
          Failure.new(X::NYI.new(
            feature => ':exists on multi-dimensional slices')),
          nqp::if(
            nqp::iseq_i($elems,2),
            SELF.EXISTS-POS(
              nqp::atpos($indices,0),
              nqp::atpos($indices,1)
            ),
            nqp::if(
              nqp::iseq_i($elems,3),
              SELF.EXISTS-POS(
                nqp::atpos($indices,0),
                nqp::atpos($indices,1),
                nqp::atpos($indices,2)
              ),
              SELF.EXISTS-POS(|@indices)
            )
          )
        )
      ),
      postcircumfix:<[; ]>(SELF, @indices)
    )
}

multi sub postcircumfix:<[; ]>(\SELF, @indices, :$delete!) is raw {
    if $delete {
        my int $elems = @indices.elems;
        my $indices := nqp::getattr(@indices,List,'$!reified');
        my int $i = -1;
        fail X::NYI.new(feature => ':delete on multi-dimensional slices')
          unless nqp::istype(nqp::atpos($indices,$i), Int)
          while nqp::islt_i(++$i,$elems);

        SELF.DELETE-POS(|@indices)
    }
    else {
        SELF[@indices]
    }
}

multi sub postcircumfix:<[; ]>(\SELF, @indices, :$BIND!) is raw {
    my int $elems = @indices.elems;
    my $indices := nqp::getattr(@indices,List,'$!reified');
    my int $i = -1;
    X::Bind::Slice.new(type => SELF.WHAT).throw
      unless nqp::istype(nqp::atpos($indices,$i), Int)
      while nqp::islt_i(++$i,$elems);

    SELF.BIND-POS(|@indices, $BIND)
}

# vim: ft=perl6 expandtab sw=4

{'fraction_non_alphanumeric': 0.1844848913235554, 'fraction_numerical': 0.006096483477646227, 'mean_word_length': 1.9323834196891192, 'pattern_counts': {'":': 0, '<': 18, '<?xml version=': 0, '>': 22, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2330573', 'n_tokens_mistral': 4276, 'n_tokens_neox': 4178, 'n_words': 655}