提交 a8b948d8 编写于 作者: A Aaron Patterson

do not compile regexp on every call

上级 66d8620e
......@@ -64,27 +64,25 @@ def cast_hstore(object)
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
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册