speed up ydecoding a little

This commit is contained in:
Ward Wouts 2002-08-17 18:58:06 +00:00
parent 7a7d053b96
commit ffe0a85311

View file

@ -719,9 +719,9 @@ def _ydecode_file(file, outfile)
total = 0
oldpartend = 0
ymap=[]
(0..255).each do |b|
ymap.push((b-42+256)%256)
ymap = {}
(-106..255).each do |b|
ymap[b]=((b-42)%256)
end
while (! file.eof)
@ -828,28 +828,11 @@ def _ydecode_file(file, outfile)
i += 1
line[i] -= 64
end
ostr << ((line[i] - 42) % 256)
# outfile.putc((line[i] - 42) % 256)
# ostr << ymap[line[i]%255]
ostr << ymap[line[i]]
i += 1
end
outfile << ostr
bytes += ostr.length
# special = 0
# line.each_byte { |b|
# if special == 0
# if b == 0x3d
# special = 1
# next
# end
# else
# special = 0
# b = (b - 64) % 256
# end
# outfile.putc((b - 42) % 256)
# bytes += 1
# }
end
print "No \"=yend\" found!!!\n"
@ -866,6 +849,11 @@ def _ydecode_array(data)
percent = 0
mark = lines/100
ymap = {}
(-106..255).each do |b|
ymap[b]=((b-42)%256)
end
i = 0
while (i < data.length)
if data[i] =~ /^\=ybegin\s+(.*line\=.*)/
@ -918,21 +906,35 @@ def _ydecode_array(data)
# print "#{i}: linesize mismatch, was #{line.length}, should be #{linesize}...\n"
# end
special = 0
str = ""
line.each_byte { |b|
if special == 0
if b == 0x3d
special = 1
next
end
else
special = 0
b = (b - 64) % 256
i = 0
ll = line.length
ostr = ''
while i < ll
if line[i] == 0x3d
i += 1
line[i] -= 64
end
str << ((b - 42) % 256).chr
}
decode << str
ostr << ymap[line[i]]
i += 1
end
decode << ostr
bytes += ostr.length
# special = 0
# str = ""
# line.each_byte { |b|
# if special == 0
# if b == 0x3d
# special = 1
# next
# end
# else
# special = 0
# b = (b - 64) % 256
# end
# str << ((b - 42) % 256).chr
# }
# decode << str
end
print "${i}: no \"=yend\" found!!!\n"