Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[src/setting/Any-str.pm] a new, shorter .bytes implementation
Patch submitted by Klaus Bruessel (Muixirt++).
  • Loading branch information
Carl Masak committed Jun 2, 2009
1 parent d03217d commit 63cc77c
Showing 1 changed file with 3 additions and 34 deletions.
37 changes: 3 additions & 34 deletions src/setting/Any-str.pm
@@ -1,40 +1,9 @@
class Any is also {
our Int multi method bytes() is export {
Q:PIR {
.local string str
.local pmc chars
.local pmc bytes
.local int count
.local string nextchar
.local int charcode
.local string hexstring
.local int hexstringlength
.local string firsttwo
str = self
chars = split '', str
bytes = new 'FixedIntegerArray'
set bytes, 1
count = 0
loop:
unless bytes goto done
nextchar = shift chars
charcode = ord nextchar
bytes[0] = charcode
hexstring = sprintf '%08x', bytes
eat_zeroes:
hexstringlength = length hexstring
if hexstringlength == 2 goto inc_length
firsttwo = substr hexstring, 0, 2
unless firsttwo == '00' goto inc_length
hexstring = substr hexstring, 2
goto eat_zeroes
inc_length:
hexstringlength = length hexstring
count += hexstringlength
goto loop
done:
count /= 2
%r = box count
$S0 = self
$I0 = bytelength $S0
%r = box $I0
}
}
Expand Down

0 comments on commit 63cc77c

Please sign in to comment.