Skip to content

Commit

Permalink
Make Blob.gist 26x faster
Browse files Browse the repository at this point in the history
  • Loading branch information
zoffixznet committed Oct 6, 2017
1 parent 96669c6 commit 20a99fc
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions src/core/Buf.pm
Original file line number Diff line number Diff line change
Expand Up @@ -136,12 +136,13 @@ my role Blob[::T = uint8] does Positional[T] does Stringy is repr('VMArray') is
}

multi method gist(Blob:D:) {
self.^name ~ ':0x<' ~ self.map( -> $elem {
given ++$ {
when 101 { '...' }
when 102 { last }
default { $elem.fmt: '%02x' }
}
self.^name ~ ':0x<' ~ self.map( -> \el {
state $i = 0;
++$i == 101 ?? '...'
!! $i == 102 ?? last()
!! nqp::if(nqp::iseq_i( # el.fmt: '%02x'
nqp::chars(my str $v = nqp::lc(el.base: 16)),1),
nqp::concat('0',$v),$v)
}) ~ '>'
}
multi method perl(Blob:D:) {
Expand Down

0 comments on commit 20a99fc

Please sign in to comment.