Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Move REMOVE-ROOT to Rakudo::Internals
and streamline with new gained knowledge  :-)
  • Loading branch information
lizmat committed Jan 11, 2016
1 parent 34d2b6f commit 308c469
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 17 deletions.
15 changes: 0 additions & 15 deletions src/core/IO.pm
Expand Up @@ -38,21 +38,6 @@ enum ProtocolType (
# obfuscated names, will have to do. They should also provide excellent
# optimizing targets.

sub REMOVE-ROOT(Str $r, Str $p) {
my str $root = nqp::unbox_s($r);
my str $path = nqp::unbox_s($p);
my int $chars = nqp::chars($root);

return $p if $chars >= nqp::chars($path); # makes no sense

my int $i;
while $i < $chars && nqp::ordat($root,$i) == nqp::ordat($path,$i) {
$i = $i + 1;
}

$i == $chars ?? nqp::box_s(nqp::substr($path,$i),Str) !! $p;
}

sub CHANGE-DIRECTORY($path,$base,&test) {

my $abspath = Rakudo::Internals.MAKE-CLEAN-PARTS(
Expand Down
8 changes: 6 additions & 2 deletions src/core/IO/Local.pm
Expand Up @@ -12,8 +12,12 @@ my role IO::Local {
method absolute(IO::Local:D:) { $!abspath }

proto method relative(|) { * }
multi method relative(IO::Local:D:) { REMOVE-ROOT($*CWD ~ '/',$!abspath) }
multi method relative(IO::Local:D: $root) { REMOVE-ROOT($root,$!abspath) }
multi method relative(IO::Local:D:) {
Rakudo::Internals.REMOVE-ROOT($*CWD ~ '/',$!abspath)
}
multi method relative(IO::Local:D: $root) {
Rakudo::Internals.REMOVE-ROOT($root,$!abspath)
}

method !parts() { @!parts = $!abspath.split('/') unless @!parts }
method volume(IO::Local:D:) {
Expand Down
9 changes: 9 additions & 0 deletions src/core/Rakudo/Internals.pm
Expand Up @@ -992,6 +992,15 @@ my class Rakudo::Internals {
nqp::push($parts,"");
$parts
}

method REMOVE-ROOT(Str:D \root, Str:D \path) {
my str $root = nqp::unbox_s(root);
my str $path = nqp::unbox_s(path);

nqp::eqat($path,$root,0)
?? nqp::p6box_s(nqp::substr($path,nqp::chars($root)))
!! path;
}
}

# vim: ft=perl6 expandtab sw=4

0 comments on commit 308c469

Please sign in to comment.