diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2011-12-20 13:59:08 -0600 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2011-12-20 14:04:51 -0600 |
commit | a8b948d81c6c7aa5beac0e98259c12c067f4bd32 (patch) | |
tree | 1177d16ce3ee7777d9fee9672c0457731c217251 /activerecord/lib/active_record | |
parent | 66d8620e3c1dcc6df5c8c648085d833ff7bdd2ff (diff) | |
download | rails-a8b948d81c6c7aa5beac0e98259c12c067f4bd32.tar.gz rails-a8b948d81c6c7aa5beac0e98259c12c067f4bd32.tar.bz2 rails-a8b948d81c6c7aa5beac0e98259c12c067f4bd32.zip |
do not compile regexp on every call
Diffstat (limited to 'activerecord/lib/active_record')
-rw-r--r-- | activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb | 30 |
1 files changed, 14 insertions, 16 deletions
diff --git a/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb b/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb index 705fc8135d..d7adcdc5d4 100644 --- a/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb +++ b/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb @@ -64,27 +64,25 @@ module ActiveRecord end private + HSTORE_ESCAPE = { + ' ' => '\\ ', + '\\' => '\\\\', + '"' => '\\"', + '=' => '\\=', + } + HSTORE_ESCAPE_RE = Regexp.union(HSTORE_ESCAPE.keys) + HSTORE_UNESCAPE = HSTORE_ESCAPE.invert + HSTORE_UNESCAPE_RE = Regexp.union(HSTORE_UNESCAPE.keys) + def unescape_hstore(value) - escape_values = { - '\\ ' => ' ', - '\\\\' => '\\', - '\\"' => '"', - '\\=' => '=', - } - value.gsub(Regexp.union(escape_values.keys)) do |match| - escape_values[match] + value.gsub(HSTORE_UNESCAPE_RE) do |match| + HSTORE_UNESCAPE[match] end end def escape_hstore(value) - escape_values = { - ' ' => '\\ ', - '\\' => '\\\\', - '"' => '\\"', - '=' => '\\=', - } - value.gsub(Regexp.union(escape_values.keys)) do |match| - escape_values[match] + value.gsub(HSTORE_ESCAPE_RE) do |match| + HSTORE_ESCAPE[match] end end end |