don't copy arrays, unless you have to

This commit is contained in:
Ward Wouts 2002-08-07 21:22:18 +00:00
parent 15a4f06afa
commit b5bed34702

View file

@ -92,12 +92,22 @@ class NNTP
putline cmd putline cmd
end end
# def getline
# line = ''
# line.concat @socket.recv 1 until line.length > 2 and line[-1] == "\n" or line[-2..-1] == "\r\n"
# puts '*getline* '+line if @debuglevel > 0
# line = line[0...-2] if line[-2..-1] == "\r\n"
# line = line[0...-1] if "\r\n".include? line[-1].to_s
# return line
# end
def getline def getline
line = '' line = ''
line.concat @socket.recv 1 until line.length > 2 and line[-1] == "\n" or line[-2..-1] == "\r\n" line = @socket.readline
puts '*getline* '+line if @debuglevel > 0 print "*getline* '#{line}'" if @debuglevel > 0
line = line[0...-2] if line[-2..-1] == "\r\n" line.chomp!("\r\n")
line = line[0...-1] if "\r\n".include? line[-1].to_s # line.sub!(/\r?\n?$/, '')
# print "*getline* matches end\n" if line == '.'
return line return line
end end
@ -113,14 +123,14 @@ class NNTP
return resp return resp
end end
def getlongresp def getlongresp
resp = getresp resp = getresp
raise NNTPReplyError, resp, caller unless LONGRESP.include? resp[0...3] raise NNTPReplyError, resp, caller unless LONGRESP.include? resp[0...3]
list = [] list = []
while true while true
line = getline line = getline
break if line == '.' break if line == '.'
line = line[1..-1] if line.to_s[0...2] == '..' line.delete_at(0) if line.to_s[0...2] == '..'
list << line list << line
end end
return resp, list return resp, list