Project

General

Profile

Bug #3514 » unused.patch

runpaint (Run Paint Run Run), 07/14/2010 04:57 AM

View differences:

lib/benchmark.rb
n = ARGV[0].to_i.nonzero? || 50000
puts %Q([#{n} times iterations of `a = "1"'])
benchmark(" " + CAPTION, 7, FMTSTR) do |x|
x.report("for:") {for i in 1..n; a = "1"; end} # Benchmark::measure
x.report("times:") {n.times do ; a = "1"; end}
x.report("upto:") {1.upto(n) do ; a = "1"; end}
x.report("for:") {for _ in 1..n; _ = "1"; end} # Benchmark::measure
x.report("times:") {n.times do ; _ = "1"; end}
x.report("upto:") {1.upto(n) do ; _ = "1"; end}
end
benchmark do
[
measure{for i in 1..n; a = "1"; end}, # Benchmark::measure
measure{n.times do ; a = "1"; end},
measure{1.upto(n) do ; a = "1"; end}
measure{for _ in 1..n; _ = "1"; end}, # Benchmark::measure
measure{n.times do ; _ = "1"; end},
measure{1.upto(n) do ; _ = "1"; end}
]
end
end
lib/drb/ssl.rb
end
def self.open(uri, config)
host, port, option = parse_uri(uri)
host, port, = parse_uri(uri)
host.untaint
port.untaint
soc = TCPSocket.open(host, port)
......
def self.open_server(uri, config)
uri = 'drbssl://:0' unless uri
host, port, opt = parse_uri(uri)
host, port, = parse_uri(uri)
if host.size == 0
host = getservername
soc = open_server_inaddr_any(host, port)
lib/drb/timeridconv.rb
def keeper
Thread.new do
loop do
size = alternate
alternate
sleep(@timeout)
end
end
lib/drb/unix.rb
end
def self.open(uri, config)
filename, option = parse_uri(uri)
filename, = parse_uri(uri)
filename.untaint
soc = UNIXSocket.open(filename)
self.new(uri, soc, config)
end
def self.open_server(uri, config)
filename, option = parse_uri(uri)
filename, = parse_uri(uri)
if filename.size == 0
soc = temp_server
filename = soc.path
lib/irb/ext/multi-irb.rb
end
def thread(key)
th, irb = search(key)
th, = search(key)
th
end
def irb(key)
th, irb = search(key)
_, irb = search(key)
irb
end
......
def kill(*keys)
for key in keys
th, irb = search(key)
th, _ = search(key)
IRB.fail IrbAlreadyDead unless th.alive?
th.exit
end
lib/irb/ws-for-case-2.rb
#
while true
IRB::BINDING_QUEUE.push b = binding
IRB::BINDING_QUEUE.push _ = binding
end
lib/minitest/mock.rb
end
def expect(name, retval, args=[])
n, r, a = name, retval, args # for the closure below
n, r, = name, retval, args # for the closure below
@expected_calls[name] = { :retval => retval, :args => args }
self.class.__send__ :remove_method, name if respond_to? name
self.class.__send__(:define_method, name) { |*x|
lib/net/ftp.rb
sock = TCPServer.open(@sock.addr[3], 0)
port = sock.addr[1]
host = sock.addr[3]
resp = sendport(host, port)
sendport(host, port)
return sock
end
private :makeport
lib/net/http.rb
# or sub-type is not given (e.g. "Content-Type: text").
def sub_type
return nil unless @header['content-type']
main, sub = *self['Content-Type'].split(';').first.to_s.split('/')
_, sub = *self['Content-Type'].split(';').first.to_s.split('/')
return nil unless sub
sub.strip
end
lib/net/imap.rb
token = match(T_ATOM)
name = token.value.upcase
match(T_SPACE)
mailbox = astring
data = []
token = lookahead
if token.symbol == T_SPACE
lib/open-uri.rb
def OpenURI.open_uri(name, *rest) # :nodoc:
uri = URI::Generic === name ? name : URI.parse(name)
mode, perm, rest = OpenURI.scan_open_optional_arguments(*rest)
mode, _, rest = OpenURI.scan_open_optional_arguments(*rest)
options = rest.shift if !rest.empty? && Hash === rest.first
raise ArgumentError.new("extra arguments") if !rest.empty?
options ||= {}
......
# It is downcased for canonicalization.
# Content-Type parameters are stripped.
def content_type
type, *parameters = content_type_parse
type, = content_type_parse
type || 'application/octet-stream'
end
......
when 0 # no proxy setting anyway.
proxy_uri = nil
when 1
k, v = pairs.shift
k, = pairs.shift
if k == 'http_proxy' && ENV[k.upcase] == nil
# http_proxy is safe to use because ENV is case sensitive.
proxy_uri = ENV[name]
lib/optparse.rb
default_style = Switch::NoArgument
default_pattern = nil
klass = nil
n, q, a = nil
q, a = nil
opts.each do |o|
# argument class
lib/racc/parser.rb
def _racc_do_parse_rb(arg, in_debug)
action_table, action_check, action_default, action_pointer,
goto_table, goto_check, goto_default, goto_pointer,
nt_base, reduce_table, token_table, shift_n,
reduce_n, use_result, * = arg
_, _, _, _,
_, _, token_table, _,
_, _, * = arg
_racc_init_sysvars
tok = act = i = nil
nerr = 0
catch(:racc_end_parse) {
while true
......
def _racc_yyparse_rb(recv, mid, arg, c_debug)
action_table, action_check, action_default, action_pointer,
goto_table, goto_check, goto_default, goto_pointer,
nt_base, reduce_table, token_table, shift_n,
reduce_n, use_result, * = arg
_, _, _, _,
_, _, token_table, _,
_, _, * = arg
_racc_init_sysvars
act = nil
i = nil
nerr = 0
catch(:racc_end_parse) {
until i = action_pointer[@racc_state[-1]]
......
###
def _racc_evalact(act, arg)
action_table, action_check, action_default, action_pointer,
goto_table, goto_check, goto_default, goto_pointer,
nt_base, reduce_table, token_table, shift_n,
reduce_n, use_result, * = arg
action_table, action_check, _, action_pointer,
_, _, _, _,
_, _, _, shift_n, reduce_n,
_, * = arg
nerr = 0 # tmp
if act > 0 and act < shift_n
......
end
def _racc_do_reduce(arg, act)
action_table, action_check, action_default, action_pointer,
_, _, _, _,
goto_table, goto_check, goto_default, goto_pointer,
nt_base, reduce_table, token_table, shift_n,
reduce_n, use_result, * = arg
nt_base, reduce_table, _, _,
_, use_result, * = arg
state = @racc_state
vstack = @racc_vstack
tstack = @racc_tstack
lib/rake.rb
else
begin
ln(*args)
rescue StandardError, NotImplementedError => ex
rescue StandardError, NotImplementedError
LN_SUPPORTED[0] = false
cp(*args)
end
......
end
def create_rule(*args, &block)
pattern, arg_names, deps = resolve_args(args)
pattern, _, deps = resolve_args(args)
pattern = Regexp.new(Regexp.quote(pattern) + '$') if String === pattern
@rules << [pattern, deps, block]
end
......
fail Rake::RuleRecursionOverflowError,
"Rule Recursion Too Deep" if level >= 16
@rules.each do |pattern, extensions, block|
if md = pattern.match(task_name)
if pattern.match(task_name)
task = attempt_rule(task_name, extensions, block, level)
return task if task
end
......
rescue LoadError => ex
begin
rake_require value
rescue LoadError => ex2
rescue LoadError
raise ex
end
end
lib/rake/contrib/ftptools.rb
def initialize(path, entry)
@path = path
@mode, line, @owner, @group, size, d1, d2, d3, @name = entry.split(' ')
@mode, _, @owner, @group, size, d1, d2, d3, @name = entry.split(' ')
@size = size.to_i
@time = determine_time(d1, d2, d3)
end
......
def determine_time(d1, d2, d3)
now = self.class.time.now
if /:/ =~ d3
h, m = d3.split(':')
result = Time.parse("#{d1} #{d2} #{now.year} #{d3}")
if result > now
result = Time.parse("#{d1} #{d2} #{now.year-1} #{d3}")
lib/rdoc/markup/attribute_manager.rb
def split_into_flow
res = []
current_attr = 0
str = ""
str_len = @str.length
lib/rdoc/markup/parser.rb
# Skips a token of +token_type+, optionally raising an error.
def skip token_type, error = true
type, data, = get
type, = get
return unless type # end of stream
lib/rdoc/parser/c.rb
\s*(\([^)]*\))([^;]|$))"xm
comment = $1
body_text = $2
params = $3
remove_private_comments comment if comment
......
find_modifiers comment, meth_obj if comment
#meth_obj.params = params
meth_obj.start_collecting_tokens
tk = RDoc::RubyToken::Token.new nil, 1, 1
tk.set_text body_text
lib/rdoc/parser/ruby.rb
def parse_attr_accessor(context, single, tk, comment)
args = parse_symbol_arg
read = get_tkread
rw = "?"
# TODO If nodoc is given, don't document any of them
......
def parse_meta_attr(context, single, tk, comment)
args = parse_symbol_arg
read = get_tkread
rw = "?"
# If nodoc is given, don't document any of them
lib/rdoc/rdoc.rb
@generator = gen_klass.for @options
pwd = Dir.pwd
Dir.chdir @options.op_dir do
begin
self.class.current = self
lib/rdoc/ruby_lex.rb
tk_c = TkLPAREN
end
@indent_stack.push tk_c
tk = Token(tk_c)
Token(tk_c)
end
@OP.def_rule("[]", proc{|op, io| @lex_state == EXPR_FNAME}) do
lib/resolv-replace.rb
rescue Resolv::ResolvError
raise SocketError, "Hostname not known: #{host}"
end
err = nil
addrs[0...-1].each {|addr|
begin
return original_resolv_send(mesg, flags, addr, port)
lib/rexml/attribute.rb
def doctype
if @element
doc = @element.document
doctype = doc.doctype if doc
doc.doctype if doc
end
end
lib/rexml/child.rb
# This doesn't yet handle encodings
def bytes
encoding = document.encoding
document.encoding
to_s
end
lib/rexml/doctype.rb
output << " #{@long_name.inspect}" if @long_name
output << " #{@uri.inspect}" if @uri
unless @children.empty?
next_indent = indent + 1
output << ' ['
@children.each { |child|
output << "\n"
lib/rexml/element.rb
# a.elements.add(Element.new('b')) #-> <a><b/></a>
# a.elements.add('c') #-> <a><b/><c/></a>
def add element=nil
rv = nil
if element.nil?
Element.new("", self, @element.context)
elsif not element.kind_of?(Element)
......
delete attr
return
end
element_document = @element.document
unless value.kind_of? Attribute
if @element.document and @element.document.doctype
value = Text::normalize( value, @element.document.doctype )
......
return @element
else # the supplied attribute is a top-level one
attr = old
res = super(name)
super(name)
end
@element
end
lib/rexml/formatters/transitive.rb
# If compact and all children are text, and if the formatted output
# is less than the specified width, then try to print everything on
# one line
skip = false
@level += @indentation
node.children.each { |child|
write( child, output )
lib/rexml/functions.rb
# Kouhei fixed this too
def Functions::substring_after( string, test )
ruby_string = string(string)
test_string = string(test)
return $1 if ruby_string =~ /#{test}(.*)/
""
end
lib/rexml/parsers/sax2parser.rb
@listeners.each { |sym,match,block|
block.start_document if sym == :start_document or sym.nil?
}
root = context = []
context = []
while true
event = @parser.pull
case event[0]
lib/rexml/parsers/xpathparser.rb
PI = /^processing-instruction\(/
def NodeTest path, parsed
#puts "NodeTest with #{path}"
res = nil
case path
when /^\*/
path = $'
......
NUMBER = /^(\d*\.?\d+)/
NT = /^comment|text|processing-instruction|node$/
def PrimaryExpr path, parsed
arry = []
case path
when VARIABLE_REFERENCE
varname = $1
lib/rexml/quickpath.rb
results = filter(element.to_a, path)
when /^[\[!\w:]/u
# match on child
matches = []
children = element.to_a
results = filter(children, path)
else
......
when /^\/\//u # Descendant
return axe( elements, "descendant-or-self", $' )
when /^\/?\b(\w[-\w]*)\b::/u # Axe
axe_name = $1
rest = $'
return axe( elements, $1, $' )
when /^\/(?=\b([:!\w][-\.\w]*:)?[-!\*\.\w]*\b([^:(]|$)|\*)/u # Child
rest = $'
lib/rexml/validation/validation.rb
sattr = [:start_attribute, nil]
eattr = [:end_attribute]
text = [:text, nil]
k,v = event[2].find { |key,value|
k, = event[2].find { |key,value|
sattr[1] = key
#puts "Looking for #{sattr.inspect}"
m = @current.next( sattr )
lib/rexml/xpath_parser.rb
return rv
else
res = []
enum = SyncEnumerator.new( set1, set2 ).each { |i1, i2|
SyncEnumerator.new( set1, set2 ).each { |i1, i2|
#puts "i1 = #{i1.inspect} (#{i1.class.name})"
#puts "i2 = #{i2.inspect} (#{i2.class.name})"
i1 = norm( i1 )
lib/rinda/ring.rb
def lookup_ring_any(timeout=5)
queue = Queue.new
th = Thread.new do
Thread.new do
self.lookup_ring(timeout) do |ts|
queue.push(ts)
end
......
when 's'
require 'rinda/tuplespace'
ts = Rinda::TupleSpace.new
place = Rinda::RingServer.new(ts)
Rinda::RingServer.new(ts)
$stdin.gets
when 'w'
finger = Rinda::RingFinger.new(nil)
lib/rss/atom.rb
return false unless inline_other?
return false if inline_other_xml?
media_type, subtype = mime_split
media_type, = mime_split
return true if "text" == media_type.downcase
false
end
lib/rss/maker/0.9.rb
class Channel < ChannelBase
def to_feed(rss)
channel = Rss::Channel.new
set = setup_values(channel)
setup_values(channel)
_not_set_required_variables = not_set_required_variables
if _not_set_required_variables.empty?
rss.channel = channel
......
class Item < ItemBase
def to_feed(rss)
item = Rss::Channel::Item.new
set = setup_values(item)
setup_values(item)
_not_set_required_variables = not_set_required_variables
if _not_set_required_variables.empty?
rss.items << item
lib/rss/maker/1.0.rb
_not_set_required_variables = not_set_required_variables
if _not_set_required_variables.empty?
channel = RDF::Channel.new(@about)
set = setup_values(channel)
setup_values(channel)
channel.dc_dates.clear
rss.channel = channel
set_parent(channel, rss)
lib/rss/maker/dublincore.rb
plural_name ||= "#{name}s"
full_name = "#{RSS::DC_PREFIX}_#{name}"
full_plural_name = "#{RSS::DC_PREFIX}_#{plural_name}"
klass_name = Utils.to_class_name(name)
plural_klass_name = "DublinCore#{Utils.to_class_name(plural_name)}"
full_plural_klass_name = "self.class::#{plural_klass_name}"
full_klass_name = "#{full_plural_klass_name}::#{klass_name}"
klass.def_classed_elements(full_name, "value", plural_klass_name,
full_plural_name, name)
klass.module_eval(<<-EOC, __FILE__, __LINE__ + 1)
lib/rss/rss.rb
tags = tags.sort_by {|x| element_names.index(x) || tags_size}
end
_tags = tags.dup if tags
models.each_with_index do |model, i|
name, model_uri, occurs, getter = model
name, _, occurs, = model
if DEBUG
p "before"
lib/rubygems/command.rb
"Please specify at least one gem name (e.g. gem build GEMNAME)"
end
gem_names = args.select { |arg| arg !~ /^-/ }
args.select { |arg| arg !~ /^-/ }
end
##
......
@parser.separator " #{header}Options:"
option_list.each do |args, handler|
dashes = args.select { |arg| arg =~ /^-/ }
args.select { |arg| arg =~ /^-/ }
@parser.on(*args) do |value|
handler.call(value, @options)
end
lib/rubygems/commands/build_command.rb
while not f.eof? and spec = Gem::Specification.from_yaml(f)
result << spec
end
rescue Gem::EndOfYAMLException => e
rescue Gem::EndOfYAMLException
# OK
end
end
lib/rubygems/commands/check_command.rb
say "Verifying gem: '#{gem_name}'"
begin
Gem::Validator.new.verify_gem_file(gem_name)
rescue Exception => e
rescue Exception
alert_error "#{gem_name} is invalid."
end
end
lib/rubygems/commands/query_command.rb
end
versions.each do |gem_name, matching_tuples|
matching_tuples = matching_tuples.sort_by do |(name, version,_),_|
matching_tuples = matching_tuples.sort_by do |(_, version,_),_|
version
end.reverse
platforms = Hash.new { |h,version| h[version] = [] }
matching_tuples.map do |(name, version, platform,_),_|
matching_tuples.map do |(_, version, platform,_),_|
platforms[version] << platform if platform
end
seen = {}
matching_tuples.delete_if do |(name, version,_),_|
matching_tuples.delete_if do |(_, version,_),_|
if seen[version] then
true
else
......
if options[:versions] then
list = if platforms.empty? or options[:details] then
matching_tuples.map { |(name, version,_),_| version }.uniq
matching_tuples.map { |(_, version,_),_| version }.uniq
else
platforms.sort.reverse.map do |version, pls|
if pls == [Gem::Platform::RUBY] then
lib/rubygems/commands/server_command.rb
else
begin
Socket.getservbyname port
rescue SocketError => e
rescue SocketError
raise OptionParser::InvalidArgument, "#{port}: no such named service"
end
end
lib/rubygems/commands/update_command.rb
end
end
matching_gems = spec_tuples.select do |(name, version, platform),|
matching_gems = spec_tuples.select do |(name, _, platform),|
name == l_name and Gem::Platform.match platform
end
highest_remote_gem = matching_gems.sort_by do |(name, version),|
highest_remote_gem = matching_gems.sort_by do |(_, version),|
version
end.last
lib/rubygems/doc_manager.rb
:formatter => RDoc::RI::Formatter,
}
driver = RDoc::RI::Driver.new(options).class_cache
RDoc::RI::Driver.new(options).class_cache
end
##
lib/rubygems/format.rb
# representing the data in the gem
def self.from_file_by_path(file_path, security_policy = nil)
format = nil
unless File.exist?(file_path)
raise Gem::Exception, "Cannot load gem at [#{file_path}] in #{Dir.pwd}"
end
lib/rubygems/gem_openssl.rb
# Reference a constant defined in the .rb portion of ssl (just to
# make sure that part is loaded too).
dummy = OpenSSL::Digest::SHA1
OpenSSL::Digest::SHA1
Gem.ssl_available = true
lib/rubygems/installer.rb
def generate_bin_script(filename, bindir)
bin_script_path = File.join bindir, formatted_program_filename(filename)
exec_path = File.join @gem_dir, @spec.bindir, filename
File.join @gem_dir, @spec.bindir, filename
# HACK some gems don't have #! in their executables, restore 2008/06
#if File.read(exec_path, 2) == '#!' then
......
say results.join("\n") if Gem.configuration.really_verbose
rescue => ex
rescue
results = results.join "\n"
File.open('gem_make.out', 'wb') { |f| f.puts results }
lib/rubygems/old_format.rb
end
yield [entry, Zlib::Inflate.inflate(file_data.strip.unpack("m")[0])]
end
rescue Zlib::DataError => e
rescue Zlib::DataError
raise Gem::Exception, errstr
end
end
lib/rubygems/source_index.rb
begin
fetcher = Gem::SpecFetcher.fetcher
remotes = fetcher.find_matching dependency
remotes = remotes.map { |(name, version,_),_| version }
remotes = remotes.map { |(_, version, _),_| version }
rescue Gem::RemoteFetcher::FetchError => e
raise unless fetcher.warn_legacy e do
require 'rubygems/source_info_cache'
lib/rubygems/specification.rb
private :same_attributes?
def hash # :nodoc:
@@attributes.inject(0) { |hash_code, (name, default_value)|
@@attributes.inject(0) { |hash_code, (name, _)|
n = self.send(name).hash
hash_code + n
}
......
def to_yaml(opts = {}) # :nodoc:
return super if YAML.const_defined?(:ENGINE) && !YAML::ENGINE.syck?
yaml = YAML.quick_emit object_id, opts do |out|
YAML.quick_emit object_id, opts do |out|
out.map taguri, to_yaml_style do |map|
encode_with map
end
lib/rubygems/uninstaller.rb
gem_names = list.collect {|gem| gem.full_name} + ["All versions"]
say
gem_name, index = choose_from_list "Select gem to uninstall:", gem_names
_, index = choose_from_list "Select gem to uninstall:", gem_names
if index == list.size then
remove_all list.dup
lib/shell/system-command.rb
notify "Job(%id) start imp-pipe.", @shell.debug?
rs = @shell.record_separator unless rs
_eop = true
th = Thread.start {
Thread.start {
begin
while l = @pipe_in.gets
@input_queue.push l
......
def start_export
notify "job(%id) start exp-pipe.", @shell.debug?
_eop = true
th = Thread.start{
Thread.start{
begin
@input.each do |l|
ProcessController::block_output_synchronize do
lib/sync.rb
def sync_try_lock(mode = EX)
return unlock if mode == UN
@sync_mutex.synchronize do
ret = sync_try_lock_sub(mode)
sync_try_lock_sub(mode)
end
ret
end
def sync_lock(m = EX)
lib/uri/common.rb
ret[:REL_URI] = rel_uri = "(?:#{net_path}|#{abs_path}|#{rel_path})(?:\\?#{query})?"
# URI-reference = [ absoluteURI | relativeURI ] [ "#" fragment ]
ret[:URI_REF] = uri_ref = "(?:#{abs_uri}|#{rel_uri})?(?:##{fragment})?"
ret[:URI_REF] = "(?:#{abs_uri}|#{rel_uri})?(?:##{fragment})?"
ret[:X_ABS_URI] = "
(#{scheme}): (?# 1: scheme)
lib/webrick/cgi.rb
setup_header
@header_part << CRLF
@header_part.rewind
rescue Exception => ex
rescue Exception
raise CGIError, "invalid CGI environment"
end
end
lib/webrick/httpresponse.rb
if @request_method == "HEAD"
# do nothing
elsif chunked?
remain = body ? @body.bytesize : 0
body ? @body.bytesize : 0
while buf = @body[@sent_size, @buffer_size]
break if buf.empty?
data = ""
lib/webrick/httpservlet/cgi_runner.rb
STDIN.binmode
buf = ""
len = sysread(STDIN, 8).to_i
out = sysread(STDIN, len)
STDOUT.reopen(open(out, "w"))
......
dir = File::dirname(ENV["SCRIPT_FILENAME"])
Dir::chdir dir
if interpreter = ARGV[0]
if ARGV[0]
argv = ARGV.dup
argv << ENV["SCRIPT_FILENAME"]
exec(*argv)
lib/webrick/httpservlet/erbhandler.rb
private
def evaluate(erb, servlet_request, servlet_response)
Module.new.module_eval{
meta_vars = servlet_request.meta_vars
query = servlet_request.query
servlet_request.meta_vars
servlet_request.query
erb.result(binding)
}
end
lib/webrick/log.rb
private
def format(arg)
str = if arg.is_a?(Exception)
if arg.is_a?(Exception)
"#{arg.class}: #{arg.message}\n\t" <<
arg.backtrace.join("\n\t") << "\n"
elsif arg.respond_to?(:to_str)
lib/xmlrpc/httpserver.rb
io << http_resp(response.status, response.status_message,
response.header, response.body)
rescue Exception => e
rescue Exception
io << http_resp(500, "Internal Server Error")
end
lib/xmlrpc/parser.rb
end
def parse(str)
parser = REXML::Document.parse_stream(str, self)
REXML::Document.parse_stream(str, self)
end
end
(8-8/8)