From fdd4a45195bb642d87c505226f7efd14e07f9a81 Mon Sep 17 00:00:00 2001 From: Ward Wouts Date: Mon, 5 Aug 2002 21:01:17 +0000 Subject: [PATCH] try to speed up ydecoding --- trunk/ripnews/news/article.rb | 43 ++++++++++++++++++++++++----------- 1 file changed, 30 insertions(+), 13 deletions(-) diff --git a/trunk/ripnews/news/article.rb b/trunk/ripnews/news/article.rb index f4af412..19fd9a4 100644 --- a/trunk/ripnews/news/article.rb +++ b/trunk/ripnews/news/article.rb @@ -255,6 +255,7 @@ def get_body(server, message) rescue Net::NNTPReplyError print "Caught Net::NNTPReplyError reading article #{message} from #{server} (get_body)\n" print "Error: #{$!}\n" + print "Status: #{$?}\n" return false rescue EOFError print "Caught EOFError reading article #{message} from #{server} (get_body)\n" @@ -710,6 +711,11 @@ def _ydecode_file(file, outfile) total = 0 oldpartend = 0 + ymap=[] + (0..255).each do |b| + ymap.push((b-42+256)%256) + end + while (! file.eof) line = file.gets print "line: #{line}" if Debuglevel > 0 @@ -747,7 +753,7 @@ def _ydecode_file(file, outfile) while (! file.eof) print "at #{file.pos} need to go to #{lines}\n" if Debuglevel > 1 line = file.gets - line = line[0 ... line.length - 1] + line.chomp! if line =~ /^=yend\s+(.*)\Z/ m = $1 @@ -805,20 +811,31 @@ def _ydecode_file(file, outfile) # if line.length != linesize # print "linesize mismatch, was #{line.length}, should be #{linesize}...\n" # end - special = 0 - line.each_byte { |b| - if special == 0 - if b == 0x3d - special = 1 - next - end - else - special = 0 - b = (b - 64) % 256 + + i = 0 + while i < line.length + if line[i] == '=' + i += 1 + line[i] -= 64 end - outfile.putc((b - 42) % 256) + outfile.putc ymap[line[i]] bytes += 1 - } + end + +# 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"