Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Revert previous 2 commits: no speed gain after all
Not sure why, but probably the extra sub call in .chomp did it.
  • Loading branch information
lizmat committed Sep 14, 2015
1 parent 1391588 commit 29cffa2
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 24 deletions.
5 changes: 2 additions & 3 deletions src/core/IO/Handle.pm
Expand Up @@ -357,8 +357,7 @@ my class IO::Handle does IO {
else {
nqp::bindattr_i($!handle, IO::Handle, '$!ins',
nqp::add_i(nqp::getattr_i($!handle, IO::Handle, '$!ins'), 1));
# XXX until we have nqp::readlinefhchomp
CHOPCRLF(nqp::readlinefh($!PIO));
nqp::p6box_s(nqp::readlinefh($!PIO)).chomp
}
}
}.new(self, $close));
Expand All @@ -373,7 +372,7 @@ my class IO::Handle does IO {
else {
nqp::bindattr_i($!handle, IO::Handle, '$!ins',
nqp::add_i(nqp::getattr_i($!handle, IO::Handle, '$!ins'), 1));
nqp::readlinefh($!PIO);
nqp::p6box_s(nqp::readlinefh($!PIO))
}
}
}.new(self, $close));
Expand Down
40 changes: 19 additions & 21 deletions src/core/Str.pm
Expand Up @@ -36,26 +36,6 @@ sub NORMALIZE_ENCODING(Str:D $s) {
%map{$s} // %map{lc $s} // lc $s;
}

# XXX this can probably go when we have nqp::readlinefhchomp
sub CHOPCRLF(\string) {
my int $chars = nqp::chars(string);
return '' if $chars == 0;

my int $last = nqp::ordat(string, $chars - 1);
if nqp::iseq_i($last, 10) {
nqp::substr(string, 0, $chars -
(nqp::isgt_i($chars, 1)
&& nqp::iseq_i(nqp::ordat(string, $chars - 2), 13) ?? 2 !! 1)
);
}
elsif nqp::iseq_i($last, 13) {
nqp::substr(string, 0, $chars - 1);
}
else {
string;
}
}

my class Str does Stringy { # declared in BOOTSTRAP
# class Str is Cool {
# has str $!value is box_target;
Expand Down Expand Up @@ -97,7 +77,25 @@ my class Str does Stringy { # declared in BOOTSTRAP
}

method chomp(Str:D:) {
nqp::p6box_s(CHOPCRLF(nqp::unbox_s(self)));
my str $sself = nqp::unbox_s(self);
my int $chars = nqp::chars($sself);
return '' if $chars == 0;

my int $last = nqp::ordat($sself, $chars - 1);
if $last == 10 {
if $chars > 1 && nqp::iseq_i(nqp::ordat($sself, $chars - 2), 13) {
nqp::p6box_s(nqp::substr($sself, 0, $chars - 2));
}
else {
nqp::p6box_s(nqp::substr($sself, 0, $chars - 1));
}
}
elsif $last == 13 {
nqp::p6box_s(nqp::substr($sself, 0, $chars - 1));
}
else {
self;
}
}

method chop(Str:D: Int() $chopping = 1) {
Expand Down

0 comments on commit 29cffa2

Please sign in to comment.