ruby/ruby — pull request #331 by bbxiao1 (2013-06-18 21:49:11+00:00)
Title: Performance change: should only attempt unescaping if escape character may be present

Encoding changes from 1.8 to 1.9 has made calls to CGI::unescapeHTML more expensive, even if no escaping needs to be done. While a few calls will have negligible difference, unescaping each line of a large CSV file will cause the losses to stack up.

Benchmarking
```ruby
require 'cgi'
require 'benchmark'

Benchmark.bm(5) do |x|
puts RUBY_VERSION
string = CGI.escapeHTML("A") # => "A"
x.report("CGI::unescapeHTML") do
100_000.times do
CGI.unescapeHTML(string)
end
end
end
```

1.8.7-p371

user system total real
CGI::unescapeHTML 0.040000 0.000000 0.040000 ( 0.041975)

1.9.3-p429 (with railsexpress patches and GC tuning)

RUBY_GC_MALLOC_LIMIT=1000000000
RUBY_FREE_MIN=500000
RUBY_HEAP_MIN_SLOTS=40000

user system total real
CGI::unescapeHTML 0.120000 0.010000 0.130000 ( 0.127006)

user system total real
CGI::unescapeHTML with performance change 0.060000 0.000000 0.060000 ( 0.058035)