<commit_before>class CompUnitRepo::Local::File does CompUnitRepo::Locally {
    has Hash $!potentials;

    my $precomp := $*VM.precomp-ext;
    my %extensions =
      Perl6 => [$precomp,'pm6','pm'],
      Perl5 => [$precomp,'pm5','pm'],
      NQP   => [$precomp,'nqp'],
      JVM   => [$precomp];
    my $anyextensions = any($precomp,<pm6 pm5 pm nqp>);

    method install($source, $from?) { ... }
    method files($file, :$name, :$auth, :$ver) { ... }

    method candidates($name = /./, :$from = 'Perl6', :$file, :$auth, :$ver) {
        my @extensions := %extensions{$from};

        my @candidates;
        for ( $!potentials //= self.potentials ).keys -> $root {
            next unless $root ~~ $name;             # not right name

            my $candidate := $!potentials{$root};
            for @extensions -> $extension {
                if $candidate{$extension} -> $sig { # use this extension
                    @candidates.push: CompUnit.new(|$sig, :$extension);
                    last;
                }
            }
        }
        @candidates;
    }

    method short-id() { 'file' }

    submethod potentials {
        my Hash $potentials = {};

        for $!path.contents -> $path {
            my $file = ~$path;

            for $file.rindex(".") -> $i {
                last unless $i.defined;               # could not find any ext

                my $ext = $file.substr($i + 1);
                last unless $ext ~~ $anyextensions;   # not right ext

                my $root = $file.substr(0,$i);
                my $j := $root.rindex(IO::Spec.rootdir);
                $root = $root.substr($j + 1) if $j.defined;

                if $potentials{$root} -> $seenroot { # seen name before
                    $potentials{$ext} := \($file, :name($root) );
                }

                else {                               # first time
                    $potentials{$root}{$ext} := \($file, :name($root) );
                }
            }
        }
        $potentials;
    }
}<commit_msg>fix lookup of potential comp unit candidates<commit_after>class CompUnitRepo::Local::File does CompUnitRepo::Locally {
    has Hash $!potentials;

    my $precomp := $*VM.precomp-ext;
    my %extensions =
      Perl6 => [$precomp,'pm6','pm'],
      Perl5 => [$precomp,'pm5','pm'],
      NQP   => [$precomp,'nqp'],
      JVM   => [$precomp];
    my $anyextensions = any($precomp,<pm6 pm5 pm nqp>);

    method install($source, $from?) { ... }
    method files($file, :$name, :$auth, :$ver) { ... }

    method candidates($name = /./, :$from = 'Perl6', :$file, :$auth, :$ver) {
        my @extensions := %extensions{$from};

        my @candidates;
        for ( $!potentials //= self.potentials ).keys -> $root {
            next unless $root ~~ $name;             # not right name

            my $candidate := $!potentials{$root};
            for @extensions -> $extension {
                if $candidate{$extension} -> $sig { # use this extension
                    @candidates.push: CompUnit.new(|$sig, :$extension);
                    last;
                }
            }
        }
        @candidates;
    }

    method short-id() { 'file' }

    submethod potentials {
        my Hash $potentials = {};

        for $!path.contents -> $path {
            my $file = ~$path;

            # We loop over one element to be able to 'last' out ot if.
            for $file.rindex(".") -> $i {
                last unless $i.defined;               # could not find any ext

                my $ext = $file.substr($i + 1);
                last unless $ext ~~ $anyextensions;   # not right ext

                my $root = $file.substr(0,$i);
                my $j := $root.rindex(IO::Spec.rootdir);
                $root = $root.substr($j + 1) if $j.defined;

                $potentials{$root}{$ext} := \($file, :name($root) );
            }
        }
        $potentials;
    }
}
{'fraction_non_alphanumeric': 0.16406449961607372, 'fraction_numerical': 0.005119017148707448, 'mean_word_length': 1.5744400527009224, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 24, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5306973', 'n_tokens_mistral': 1222, 'n_tokens_neox': 1154, 'n_words': 283}