Skip to content

Commit 5953266

Browse files
committed
Merge pull request rails#15092 from kares/pg-array-parser
[postgres] include PgArrayParser directly
2 parents 354fb0b + f8d1845 commit 5953266

File tree

2 files changed

+27
-27
lines changed

2 files changed

+27
-27
lines changed

activerecord/lib/active_record/connection_adapters/postgresql/array_parser.rb

Lines changed: 13 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -9,35 +9,23 @@ module ArrayParser
99
BRACKET_OPEN = '{'
1010
BRACKET_CLOSE = '}'
1111

12-
private
13-
# Loads pg_array_parser if available. String parsing can be
14-
# performed quicker by a native extension, which will not create
15-
# a large amount of Ruby objects that will need to be garbage
16-
# collected. pg_array_parser has a C and Java extension
17-
begin
18-
require 'pg_array_parser'
19-
include PgArrayParser
20-
rescue LoadError
21-
def parse_pg_array(string)
22-
parse_data(string)
12+
def parse_pg_array(string)
13+
local_index = 0
14+
array = []
15+
while(local_index < string.length)
16+
case string[local_index]
17+
when BRACKET_OPEN
18+
local_index,array = parse_array_contents(array, string, local_index + 1)
19+
when BRACKET_CLOSE
20+
return array
2321
end
22+
local_index += 1
2423
end
2524

26-
def parse_data(string)
27-
local_index = 0
28-
array = []
29-
while(local_index < string.length)
30-
case string[local_index]
31-
when BRACKET_OPEN
32-
local_index,array = parse_array_contents(array, string, local_index + 1)
33-
when BRACKET_CLOSE
34-
return array
35-
end
36-
local_index += 1
37-
end
25+
array
26+
end
3827

39-
array
40-
end
28+
private
4129

4230
def parse_array_contents(array, string, index)
4331
is_escaping = false

activerecord/lib/active_record/connection_adapters/postgresql/column.rb

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,20 @@ def text?
2929

3030
# :stopdoc:
3131
class << self
32-
include ConnectionAdapters::PostgreSQLColumn::Cast
33-
include ConnectionAdapters::PostgreSQLColumn::ArrayParser
32+
include PostgreSQLColumn::Cast
33+
34+
# Loads pg_array_parser if available. String parsing can be
35+
# performed quicker by a native extension, which will not create
36+
# a large amount of Ruby objects that will need to be garbage
37+
# collected. pg_array_parser has a C and Java extension
38+
begin
39+
require 'pg_array_parser'
40+
include PgArrayParser
41+
rescue LoadError
42+
require 'active_record/connection_adapters/postgresql/array_parser'
43+
include PostgreSQLColumn::ArrayParser
44+
end
45+
3446
attr_accessor :money_precision
3547
end
3648
# :startdoc:

0 commit comments

Comments
 (0)