diff options
author | kares <self@kares.org> | 2014-05-13 18:51:34 +0200 |
---|---|---|
committer | kares <self@kares.org> | 2014-05-13 18:51:34 +0200 |
commit | f8d1845fc50ee4467ff156a8edadc39d7d0f2926 (patch) | |
tree | 9f8e5df15f68656b06d341273ecff92d4f2f9792 | |
parent | 0b2eee453c20ad9b725a97d145fa59d49dcd6a92 (diff) | |
download | rails-f8d1845fc50ee4467ff156a8edadc39d7d0f2926.tar.gz rails-f8d1845fc50ee4467ff156a8edadc39d7d0f2926.tar.bz2 rails-f8d1845fc50ee4467ff156a8edadc39d7d0f2926.zip |
[postgres] include PgArrayParser directly and only load/include ArrayParser if not found
-rw-r--r-- | activerecord/lib/active_record/connection_adapters/postgresql/array_parser.rb | 38 | ||||
-rw-r--r-- | activerecord/lib/active_record/connection_adapters/postgresql/column.rb | 16 |
2 files changed, 27 insertions, 27 deletions
diff --git a/activerecord/lib/active_record/connection_adapters/postgresql/array_parser.rb b/activerecord/lib/active_record/connection_adapters/postgresql/array_parser.rb index 0b218f2bfd..5394ea0b7c 100644 --- a/activerecord/lib/active_record/connection_adapters/postgresql/array_parser.rb +++ b/activerecord/lib/active_record/connection_adapters/postgresql/array_parser.rb @@ -9,35 +9,23 @@ module ActiveRecord BRACKET_OPEN = '{' BRACKET_CLOSE = '}' - private - # Loads pg_array_parser if available. String parsing can be - # performed quicker by a native extension, which will not create - # a large amount of Ruby objects that will need to be garbage - # collected. pg_array_parser has a C and Java extension - begin - require 'pg_array_parser' - include PgArrayParser - rescue LoadError - def parse_pg_array(string) - parse_data(string) + def parse_pg_array(string) + local_index = 0 + array = [] + while(local_index < string.length) + case string[local_index] + when BRACKET_OPEN + local_index,array = parse_array_contents(array, string, local_index + 1) + when BRACKET_CLOSE + return array end + local_index += 1 end - def parse_data(string) - local_index = 0 - array = [] - while(local_index < string.length) - case string[local_index] - when BRACKET_OPEN - local_index,array = parse_array_contents(array, string, local_index + 1) - when BRACKET_CLOSE - return array - end - local_index += 1 - end + array + end - array - end + private def parse_array_contents(array, string, index) is_escaping = false diff --git a/activerecord/lib/active_record/connection_adapters/postgresql/column.rb b/activerecord/lib/active_record/connection_adapters/postgresql/column.rb index 1d22b56964..82785825e5 100644 --- a/activerecord/lib/active_record/connection_adapters/postgresql/column.rb +++ b/activerecord/lib/active_record/connection_adapters/postgresql/column.rb @@ -29,8 +29,20 @@ module ActiveRecord # :stopdoc: class << self - include ConnectionAdapters::PostgreSQLColumn::Cast - include ConnectionAdapters::PostgreSQLColumn::ArrayParser + include PostgreSQLColumn::Cast + + # Loads pg_array_parser if available. String parsing can be + # performed quicker by a native extension, which will not create + # a large amount of Ruby objects that will need to be garbage + # collected. pg_array_parser has a C and Java extension + begin + require 'pg_array_parser' + include PgArrayParser + rescue LoadError + require 'active_record/connection_adapters/postgresql/array_parser' + include PostgreSQLColumn::ArrayParser + end + attr_accessor :money_precision end # :startdoc: |