picky 4.5.4 → 4.5.5
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/extconf.rb +18 -0
- data/lib/maybe_compile.rb +39 -0
- data/lib/{picky/ext/ruby19/performant.c → performant.c} +0 -0
- data/lib/picky/loader.rb +5 -1
- data/lib/picky/pool.rb +98 -0
- data/spec/lib/pool_spec.rb +75 -0
- metadata +24 -21
- data/lib/picky/ext/maybe_compile.rb +0 -9
- data/lib/picky/ext/ruby19/extconf.rb +0 -17
data/lib/extconf.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
Dir.chdir File.expand_path('..', __FILE__) do
|
2
|
+
# Information.
|
3
|
+
#
|
4
|
+
print "Compiling on Ruby 1.9"
|
5
|
+
if defined?(RbConfig)
|
6
|
+
RbConfig::MAKEFILE_CONFIG['CC'] = ENV['CC'] if ENV['CC']
|
7
|
+
print " with CC set to #{RbConfig::MAKEFILE_CONFIG['CC']}"
|
8
|
+
end
|
9
|
+
puts " into #{Dir.pwd}."
|
10
|
+
|
11
|
+
# Compile.
|
12
|
+
#
|
13
|
+
require 'mkmf'
|
14
|
+
|
15
|
+
abort 'need ruby.h' unless have_header("ruby.h")
|
16
|
+
|
17
|
+
create_makefile('performant')
|
18
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
# Note: This is handled toplevel to not confuse compilers.
|
2
|
+
#
|
3
|
+
failed = 0
|
4
|
+
|
5
|
+
begin
|
6
|
+
require File.expand_path '../performant', __FILE__
|
7
|
+
rescue LoadError => e
|
8
|
+
failed += 1
|
9
|
+
|
10
|
+
# Have Makefile built.
|
11
|
+
#
|
12
|
+
require File.expand_path '../extconf', __FILE__
|
13
|
+
|
14
|
+
# Run make.
|
15
|
+
#
|
16
|
+
Dir.chdir File.expand_path('..', __FILE__) do
|
17
|
+
puts %x(make)
|
18
|
+
end
|
19
|
+
|
20
|
+
# Try again.
|
21
|
+
#
|
22
|
+
retry if failed < 2
|
23
|
+
|
24
|
+
# Give up and inform the user.
|
25
|
+
#
|
26
|
+
puts <<-NOTE
|
27
|
+
|
28
|
+
Picky tried to compile its source on your system but failed.
|
29
|
+
Please add an issue: https://github.com/floere/picky/issues/
|
30
|
+
and copy anything into it that you think is helpful. Thanks!
|
31
|
+
|
32
|
+
See related issue: https://github.com/floere/picky/issues/81
|
33
|
+
|
34
|
+
The problem reported by the compiler was:
|
35
|
+
#{e}
|
36
|
+
|
37
|
+
NOTE
|
38
|
+
exit 1
|
39
|
+
end
|
File without changes
|
data/lib/picky/loader.rb
CHANGED
@@ -53,7 +53,7 @@ module Picky
|
|
53
53
|
def load_framework_internals
|
54
54
|
# Load compiled C code.
|
55
55
|
#
|
56
|
-
load_relative '
|
56
|
+
load_relative '../maybe_compile'
|
57
57
|
|
58
58
|
# Load extensions.
|
59
59
|
#
|
@@ -70,6 +70,10 @@ module Picky
|
|
70
70
|
load_relative 'helpers/measuring'
|
71
71
|
load_relative 'helpers/indexing'
|
72
72
|
|
73
|
+
# Extension Modules
|
74
|
+
#
|
75
|
+
load_relative 'pool'
|
76
|
+
|
73
77
|
# Calculations.
|
74
78
|
#
|
75
79
|
load_relative 'calculations/location'
|
data/lib/picky/pool.rb
ADDED
@@ -0,0 +1,98 @@
|
|
1
|
+
module Picky
|
2
|
+
|
3
|
+
# Module that handles object pool behaviour
|
4
|
+
# for you.
|
5
|
+
#
|
6
|
+
module Pool
|
7
|
+
|
8
|
+
class << self
|
9
|
+
require 'set'
|
10
|
+
@@pools = Set.new
|
11
|
+
|
12
|
+
# Add a Pool to the managed pools.
|
13
|
+
#
|
14
|
+
def add klass
|
15
|
+
@@pools << klass
|
16
|
+
end
|
17
|
+
|
18
|
+
# Releases all obtained objects.
|
19
|
+
#
|
20
|
+
def release_all
|
21
|
+
@@pools.each { |pool| pool.release_all }
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.extended klass
|
27
|
+
add klass
|
28
|
+
|
29
|
+
class << klass
|
30
|
+
#
|
31
|
+
#
|
32
|
+
def clear
|
33
|
+
@__free__ = []
|
34
|
+
@__used__ = []
|
35
|
+
end
|
36
|
+
|
37
|
+
# Obtain creates a new reference if there is no free one
|
38
|
+
# and uses an existing one if there is.
|
39
|
+
#
|
40
|
+
# (Any caches should be cleared using clear TODO in all initializers)
|
41
|
+
#
|
42
|
+
def obtain *args, &block
|
43
|
+
unless reference = @__free__.shift
|
44
|
+
reference = allocate
|
45
|
+
end
|
46
|
+
reference.send :initialize, *args, &block
|
47
|
+
@__used__ << reference
|
48
|
+
reference
|
49
|
+
end
|
50
|
+
|
51
|
+
# Releasing an instance adds it to the free pool.
|
52
|
+
# (And removes it from the used pool)
|
53
|
+
#
|
54
|
+
def release instance
|
55
|
+
@__free__ << instance
|
56
|
+
@__used__.delete instance # TODO Optimize
|
57
|
+
end
|
58
|
+
|
59
|
+
# After you have called release all, you can't
|
60
|
+
# use any reference that has formerly been obtained
|
61
|
+
# anymore.
|
62
|
+
#
|
63
|
+
def release_all
|
64
|
+
@__used__.each { |used| @__free__ << used } # TODO Optimize
|
65
|
+
@__used__.clear
|
66
|
+
end
|
67
|
+
|
68
|
+
# How many obtainable objects are there?
|
69
|
+
#
|
70
|
+
def free_size
|
71
|
+
@__free__.size
|
72
|
+
end
|
73
|
+
|
74
|
+
# How many used objects are there?
|
75
|
+
#
|
76
|
+
def used_size
|
77
|
+
@__used__.size
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
# Initialize the pool.
|
82
|
+
#
|
83
|
+
klass.clear
|
84
|
+
|
85
|
+
# Pooled objects can be released using
|
86
|
+
# object.release
|
87
|
+
#
|
88
|
+
# Note: Do not use the object in any form after the release.
|
89
|
+
#
|
90
|
+
klass.send :define_method, :release do
|
91
|
+
klass.release self
|
92
|
+
end
|
93
|
+
|
94
|
+
end
|
95
|
+
|
96
|
+
end
|
97
|
+
|
98
|
+
end
|
@@ -0,0 +1,75 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
#
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe Picky::Pool do
|
6
|
+
|
7
|
+
class PoolTest
|
8
|
+
extend Picky::Pool
|
9
|
+
|
10
|
+
attr_reader :number
|
11
|
+
|
12
|
+
def initialize number
|
13
|
+
@number = number
|
14
|
+
end
|
15
|
+
end
|
16
|
+
class OtherPoolTest
|
17
|
+
extend Picky::Pool
|
18
|
+
|
19
|
+
attr_reader :number
|
20
|
+
|
21
|
+
def initialize number
|
22
|
+
@number = number
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
context 'functional' do
|
27
|
+
before(:each) do
|
28
|
+
PoolTest.clear
|
29
|
+
OtherPoolTest.clear
|
30
|
+
end
|
31
|
+
it 'lets me get an instance' do
|
32
|
+
PoolTest.obtain(1).should be_kind_of(PoolTest)
|
33
|
+
end
|
34
|
+
it 'does not create a new reference if it has free ones' do
|
35
|
+
pt1 = PoolTest.obtain 1
|
36
|
+
pt2 = PoolTest.obtain 2
|
37
|
+
pt1.release
|
38
|
+
|
39
|
+
PoolTest.free_size.should == 1
|
40
|
+
end
|
41
|
+
it 'gives me the released reference if I try to obtain' do
|
42
|
+
pt1 = PoolTest.obtain 1
|
43
|
+
pt2 = PoolTest.obtain 2
|
44
|
+
pt1.release
|
45
|
+
|
46
|
+
PoolTest.obtain(3).number.should == 3
|
47
|
+
end
|
48
|
+
it 'releases all PoolTests if called on PoolTest' do
|
49
|
+
pt1 = PoolTest.obtain 1
|
50
|
+
PoolTest.obtain 2
|
51
|
+
OtherPoolTest.obtain 1
|
52
|
+
OtherPoolTest.obtain 2
|
53
|
+
|
54
|
+
OtherPoolTest.free_size.should == 0
|
55
|
+
|
56
|
+
PoolTest.release_all
|
57
|
+
|
58
|
+
PoolTest.obtain(3).should == pt1
|
59
|
+
OtherPoolTest.free_size.should == 0
|
60
|
+
end
|
61
|
+
it 'releases all if called on Pool' do
|
62
|
+
PoolTest.obtain 1
|
63
|
+
PoolTest.obtain 2
|
64
|
+
OtherPoolTest.obtain 1
|
65
|
+
OtherPoolTest.obtain 2
|
66
|
+
|
67
|
+
PoolTest.free_size.should == 0
|
68
|
+
|
69
|
+
described_class.release_all
|
70
|
+
|
71
|
+
PoolTest.free_size.should == 2
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: picky
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 4.5.
|
4
|
+
version: 4.5.5
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-07-
|
12
|
+
date: 2012-07-18 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec
|
16
|
-
requirement: &
|
16
|
+
requirement: &70256039582000 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,21 +21,21 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :development
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70256039582000
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: picky-client
|
27
|
-
requirement: &
|
27
|
+
requirement: &70256039580160 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ~>
|
31
31
|
- !ruby/object:Gem::Version
|
32
|
-
version: 4.5.
|
32
|
+
version: 4.5.5
|
33
33
|
type: :development
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *70256039580160
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: text
|
38
|
-
requirement: &
|
38
|
+
requirement: &70256039578680 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ! '>='
|
@@ -43,10 +43,10 @@ dependencies:
|
|
43
43
|
version: '0'
|
44
44
|
type: :runtime
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *70256039578680
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: multi_json
|
49
|
-
requirement: &
|
49
|
+
requirement: &70256039576620 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
52
52
|
- - ! '>='
|
@@ -54,10 +54,10 @@ dependencies:
|
|
54
54
|
version: '0'
|
55
55
|
type: :runtime
|
56
56
|
prerelease: false
|
57
|
-
version_requirements: *
|
57
|
+
version_requirements: *70256039576620
|
58
58
|
- !ruby/object:Gem::Dependency
|
59
59
|
name: activesupport
|
60
|
-
requirement: &
|
60
|
+
requirement: &70256039590760 !ruby/object:Gem::Requirement
|
61
61
|
none: false
|
62
62
|
requirements:
|
63
63
|
- - ~>
|
@@ -65,10 +65,10 @@ dependencies:
|
|
65
65
|
version: '3.0'
|
66
66
|
type: :runtime
|
67
67
|
prerelease: false
|
68
|
-
version_requirements: *
|
68
|
+
version_requirements: *70256039590760
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: procrastinate
|
71
|
-
requirement: &
|
71
|
+
requirement: &70256039589300 !ruby/object:Gem::Requirement
|
72
72
|
none: false
|
73
73
|
requirements:
|
74
74
|
- - ~>
|
@@ -76,10 +76,10 @@ dependencies:
|
|
76
76
|
version: '0.4'
|
77
77
|
type: :runtime
|
78
78
|
prerelease: false
|
79
|
-
version_requirements: *
|
79
|
+
version_requirements: *70256039589300
|
80
80
|
- !ruby/object:Gem::Dependency
|
81
81
|
name: rack_fast_escape
|
82
|
-
requirement: &
|
82
|
+
requirement: &70256039588020 !ruby/object:Gem::Requirement
|
83
83
|
none: false
|
84
84
|
requirements:
|
85
85
|
- - ! '>='
|
@@ -87,16 +87,18 @@ dependencies:
|
|
87
87
|
version: '0'
|
88
88
|
type: :runtime
|
89
89
|
prerelease: false
|
90
|
-
version_requirements: *
|
90
|
+
version_requirements: *70256039588020
|
91
91
|
description: Fast Ruby semantic text search engine with comfortable single field interface.
|
92
92
|
email: florian.hanke+picky@gmail.com
|
93
93
|
executables:
|
94
94
|
- picky
|
95
95
|
extensions:
|
96
|
-
- lib/
|
96
|
+
- lib/extconf.rb
|
97
97
|
extra_rdoc_files: []
|
98
98
|
files:
|
99
99
|
- aux/picky/cli.rb
|
100
|
+
- lib/extconf.rb
|
101
|
+
- lib/maybe_compile.rb
|
100
102
|
- lib/picky/analytics.rb
|
101
103
|
- lib/picky/analyzer.rb
|
102
104
|
- lib/picky/api/category/partial.rb
|
@@ -150,8 +152,6 @@ files:
|
|
150
152
|
- lib/picky/console.rb
|
151
153
|
- lib/picky/constants.rb
|
152
154
|
- lib/picky/deployment.rb
|
153
|
-
- lib/picky/ext/maybe_compile.rb
|
154
|
-
- lib/picky/ext/ruby19/extconf.rb
|
155
155
|
- lib/picky/extensions/array.rb
|
156
156
|
- lib/picky/extensions/class.rb
|
157
157
|
- lib/picky/extensions/hash.rb
|
@@ -204,6 +204,7 @@ files:
|
|
204
204
|
- lib/picky/migrations/from_30_to_31.rb
|
205
205
|
- lib/picky/performant.rb
|
206
206
|
- lib/picky/platforms/macruby.rb
|
207
|
+
- lib/picky/pool.rb
|
207
208
|
- lib/picky/query/allocation.rb
|
208
209
|
- lib/picky/query/allocations.rb
|
209
210
|
- lib/picky/query/boosts.rb
|
@@ -238,7 +239,7 @@ files:
|
|
238
239
|
- lib/tasks/statistics.rake
|
239
240
|
- lib/tasks/todo.rake
|
240
241
|
- lib/tasks/try.rake
|
241
|
-
- lib/
|
242
|
+
- lib/performant.c
|
242
243
|
- spec/aux/picky/cli_spec.rb
|
243
244
|
- spec/category_realtime_spec.rb
|
244
245
|
- spec/ext/performant_spec.rb
|
@@ -347,6 +348,7 @@ files:
|
|
347
348
|
- spec/lib/loggers/silent_spec.rb
|
348
349
|
- spec/lib/loggers/verbose_spec.rb
|
349
350
|
- spec/lib/picky_spec.rb
|
351
|
+
- spec/lib/pool_spec.rb
|
350
352
|
- spec/lib/query/allocation_spec.rb
|
351
353
|
- spec/lib/query/allocations_spec.rb
|
352
354
|
- spec/lib/query/boosts_spec.rb
|
@@ -502,6 +504,7 @@ test_files:
|
|
502
504
|
- spec/lib/loggers/silent_spec.rb
|
503
505
|
- spec/lib/loggers/verbose_spec.rb
|
504
506
|
- spec/lib/picky_spec.rb
|
507
|
+
- spec/lib/pool_spec.rb
|
505
508
|
- spec/lib/query/allocation_spec.rb
|
506
509
|
- spec/lib/query/allocations_spec.rb
|
507
510
|
- spec/lib/query/boosts_spec.rb
|
@@ -1,17 +0,0 @@
|
|
1
|
-
# Information.
|
2
|
-
#
|
3
|
-
print "Compiling on Ruby 1.9"
|
4
|
-
if defined?(RbConfig)
|
5
|
-
RbConfig::MAKEFILE_CONFIG['CC'] = ENV['CC'] if ENV['CC']
|
6
|
-
print " with CC set to #{RbConfig::MAKEFILE_CONFIG['CC']}"
|
7
|
-
end
|
8
|
-
puts "."
|
9
|
-
|
10
|
-
# Compile.
|
11
|
-
#
|
12
|
-
require 'mkmf'
|
13
|
-
|
14
|
-
abort 'need ruby.h' unless have_header("ruby.h")
|
15
|
-
|
16
|
-
dir_config('performant')
|
17
|
-
create_makefile('performant')
|