aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record
diff options
context:
space:
mode:
authorAaron Patterson <aaron.patterson@gmail.com>2011-12-20 13:59:08 -0600
committerAaron Patterson <aaron.patterson@gmail.com>2011-12-20 14:04:51 -0600
commita8b948d81c6c7aa5beac0e98259c12c067f4bd32 (patch)
tree1177d16ce3ee7777d9fee9672c0457731c217251 /activerecord/lib/active_record
parent66d8620e3c1dcc6df5c8c648085d833ff7bdd2ff (diff)
downloadrails-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.rb30
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