From ffe0a853114d9701b367c063a3bb94a9c9514777 Mon Sep 17 00:00:00 2001 From: Ward Wouts Date: Sat, 17 Aug 2002 18:58:06 +0000 Subject: [PATCH] speed up ydecoding a little --- trunk/ripnews/news/article.rb | 72 ++++++++++++++++++----------------- 1 file changed, 37 insertions(+), 35 deletions(-) diff --git a/trunk/ripnews/news/article.rb b/trunk/ripnews/news/article.rb index 1226daa..c42afc8 100644 --- a/trunk/ripnews/news/article.rb +++ b/trunk/ripnews/news/article.rb @@ -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"