haml/haml — pull request #628 by lsylvester (2013-02-12 20:06:25+00:00)
Title: Haml::Helpers.html_escape optimisation

Each time html_escape was being called it was creating a new Regexp so that it could match the encoding of the provided string and avoid warnings.

However, the warnings are only raised if we construct a regex using a fixed encoding.

Not creating the Regexp for each call to html escape makes it run faster.

```
Benchmark.bm do |x|
x.report{ 100000.times{ Haml::Helpers.html_escape("Hello World")}}
x.report{ 100000.times{ Haml::Helpers.html_escape("Hello World")}}
end

Before:
user system total real
2.780000 0.020000 2.800000 ( 2.831747)
1.560000 0.020000 1.580000 ( 1.584677)

After:
user system total real
1.520000 0.010000 1.530000 ( 1.537405)
0.230000 0.000000 0.230000 ( 0.222655)
```

I also moved the check for the ruby version outside of the method so it is only done once instead of checking every time html_escape is called