benelux 0.4.1 → 0.4.2

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGES.txt CHANGED
@@ -1,6 +1,12 @@
1
1
  BENELUX, CHANGES
2
2
 
3
3
 
4
+ #### 0.4.2 (2009-10-06) ###############################
5
+
6
+ * ADDED: JRuby support
7
+ * CHANGE: Improved performance
8
+
9
+
4
10
  #### 0.4.1 (2009-10-06) ###############################
5
11
 
6
12
  * FIXED: Nil @thread error in reporter
data/benelux.gemspec CHANGED
@@ -1,7 +1,7 @@
1
1
  @spec = Gem::Specification.new do |s|
2
2
  s.name = "benelux"
3
3
  s.rubyforge_project = 'benelux'
4
- s.version = "0.4.1"
4
+ s.version = "0.4.2"
5
5
  s.summary = "Benelux: Little freakin' timers for your Ruby codes"
6
6
  s.description = s.summary
7
7
  s.author = "Delano Mandelbaum"
@@ -45,7 +45,12 @@ module Benelux
45
45
  self.add_tags :class => @klass.to_s.to_sym,
46
46
  :meth => @meth.to_sym,
47
47
  :kind => self.class.to_s.to_sym
48
- Benelux.packed_methods << self
48
+
49
+ Benelux.packed_methods[@klass] ||= {}
50
+ Benelux.packed_methods[@klass][@meth] = self
51
+ Benelux.packed_methods[:all] ||= []
52
+ Benelux.packed_methods[:all] << self
53
+
49
54
  end
50
55
  def install_method
51
56
  raise "You need to implement this method"
@@ -76,7 +81,7 @@ module Benelux
76
81
  # generate_method. It calls <tt>@klass.module_eval</tt>
77
82
  # with the modified line number (helpful for exceptions)
78
83
  def install_method
79
- @klass.module_eval generate_packed_method, __FILE__, 89
84
+ @klass.module_eval generate_packed_method, __FILE__, 94
80
85
  end
81
86
 
82
87
  # Creates a method definition (for an eval). The
@@ -109,17 +114,15 @@ module Benelux
109
114
  class MethodCounter < MethodPacker
110
115
  attr_reader :counter
111
116
  def install_method
112
- @klass.module_eval generate_packed_method, __FILE__, 121
117
+ @klass.module_eval generate_packed_method, __FILE__, 122
113
118
  end
114
119
 
115
120
  def generate_packed_method(callblock=false)
116
121
  %Q{
117
- @@__benelux_#{@meth}_counter =
118
- Benelux.counted_method #{@klass}, :#{@meth}
119
122
  def #{@meth}(*args, &block)
120
123
  Benelux.current_track :global unless Benelux.known_thread?
121
124
  # Get a reference to this MethodCounter instance
122
- cmd = Benelux.counted_method #{@klass}, :#{@meth}
125
+ cmd = Benelux.packed_method #{@klass}, :#{@meth}
123
126
  ret = #{@aliaz}(*args, &block)
124
127
  count = cmd.determine_count(args, ret)
125
128
  Benelux.ld "COUNT(:#{@meth}): \#{count}"
data/lib/benelux.rb CHANGED
@@ -5,7 +5,7 @@ require 'thwait'
5
5
  require 'selectable'
6
6
 
7
7
  module Benelux
8
- VERSION = "0.4.1"
8
+ VERSION = "0.4.2"
9
9
  NOTSUPPORTED = [Class, Object, Kernel]
10
10
 
11
11
  class BeneluxError < RuntimeError; end
@@ -32,7 +32,7 @@ module Benelux
32
32
  attr_reader :reporter
33
33
  end
34
34
 
35
- @packed_methods = SelectableArray.new
35
+ @packed_methods = {}
36
36
  @tracks = SelectableHash.new
37
37
  @timeline = Timeline.new
38
38
  @reporter = Reporter.new
@@ -93,22 +93,13 @@ module Benelux
93
93
  def Benelux.inspect
94
94
  str = ["Benelux"]
95
95
  str << "tracks:" << Benelux.tracks.inspect
96
- str << "timers:" << Benelux.timed_methods.inspect
97
- #str << "timeline:" << Benelux.timeline.inspect
98
96
  str.join $/
99
97
  end
100
98
 
101
99
  def Benelux.supported?(klass)
102
100
  !NOTSUPPORTED.member?(klass)
103
101
  end
104
-
105
- def Benelux.timed_methods
106
- Benelux.packed_methods.filter :kind => :'Benelux::MethodTimer'
107
- end
108
102
 
109
- def Benelux.counted_methods
110
- Benelux.packed_methods.filter :kind => :'Benelux::MethodCounter'
111
- end
112
103
 
113
104
  def Benelux.known_thread?(t=Thread.current)
114
105
  @reporter.thwait.threads.member? t
@@ -123,35 +114,17 @@ module Benelux
123
114
  end
124
115
 
125
116
  def Benelux.packed_method(klass, meth)
126
- Benelux.packed_methods.filter(klass.to_s.to_sym, meth).first
127
- end
128
-
129
- def Benelux.counted_method(klass, meth)
130
- Benelux.counted_methods.filter(klass.to_s.to_sym, meth).first
117
+ return nil unless defined?(Benelux.packed_methods[klass][meth])
118
+ Benelux.packed_methods[klass][meth]
131
119
  end
132
120
 
133
- def Benelux.timed_method(klass, meth)
134
- Benelux.timed_methods.filter(klass.to_s.to_sym, meth).first
121
+ def Benelux.packed_method? klass, meth
122
+ !Benelux.packed_method(klass, meth).nil?
135
123
  end
136
124
 
137
- def Benelux.timed_method? klass, meth
138
- Benelux.packed_method? klass, meth, :'Benelux::MethodTimer'
139
- end
140
-
141
- def Benelux.counted_method? klass, meth
142
- Benelux.packed_method? klass, meth, :'Benelux::MethodCounter'
143
- end
144
-
145
- def Benelux.packed_method? klass, meth, kind=nil
146
- list = Benelux.packed_methods.filter(klass.to_s.to_sym, meth)
147
- list.filter! :kind => kind unless kind.nil?
148
- !list.empty?
149
- end
150
-
151
-
152
125
  def Benelux.add_timer klass, meth, &blk
153
126
  raise NotSupported, klass unless Benelux.supported? klass
154
- raise AlreadyTimed, klass if Benelux.timed_method? klass, meth
127
+ raise AlreadyTimed, klass if Benelux.packed_method? klass, meth
155
128
  Benelux::MethodTimer.new klass, meth, &blk
156
129
  end
157
130
 
@@ -163,25 +136,6 @@ module Benelux
163
136
  def Benelux.ld(*msg)
164
137
  @@logger.puts "D: " << msg.join("#{$/}D: ") if debug?
165
138
  end
166
-
167
-
168
- # Returns an Array of method names for the current class that
169
- # are timed by Benelux.
170
- #
171
- # This is an instance method for objects which have Benelux
172
- # modified methods.
173
- def timed_methods
174
- Benelux.timed_methods.filter(:class => self.class.to_s.to_sym)
175
- end
176
-
177
- # Returns an Array of method names for the current class that
178
- # are counted by Benelux.
179
- #
180
- # This is an instance method for objects which have Benelux
181
- # modified methods.
182
- def counted_methods
183
- Benelux.counted_methods.filter(:class => self.class.to_s.to_sym)
184
- end
185
139
 
186
140
 
187
141
  def Benelux.enable_debug; @@debug = true; end
@@ -13,7 +13,7 @@ module Selectable
13
13
  attr_accessor :tags
14
14
  def add_tags(tags)
15
15
  init_tags!
16
- @tags.merge! Selectable.normalize tags
16
+ @tags.merge! tags
17
17
  end
18
18
  alias_method :add_tag, :add_tags
19
19
  def add_tags_quick(tags)
@@ -31,7 +31,11 @@ module Selectable
31
31
 
32
32
  def ==(other)
33
33
  if other.is_a?(Array)
34
- self.values.sort == other.sort
34
+ # NOTE: This resolves the issue of sorting an Array
35
+ # with a mix of Object types (Integers, Strings, Symbols).
36
+ # As in: self.values.sort == other.sort)
37
+ (self.values.size == other.size) &&
38
+ (self.values - other).empty?
35
39
  else
36
40
  super(other)
37
41
  end
data/lib/selectable.rb CHANGED
@@ -20,11 +20,15 @@ module Selectable
20
20
  def Selectable.normalize(*tags)
21
21
  tags.flatten!
22
22
  tags = tags.first if tags.first.kind_of?(Hash) || tags.first.kind_of?(Array)
23
- if tags.is_a?(Hash)
24
- tags = Hash[tags.collect { |n,v| [n, v.to_s] }]
25
- else
26
- tags.collect! { |v| v.to_s }
27
- end
23
+ # NOTE: The string enforcement is disabled
24
+ # FOR NOW.
25
+ #if tags.is_a?(Hash)
26
+ # #tmp = {}
27
+ # #tags.each_pair { |n,v| tmp[n] = v.to_s }
28
+ # #tags = tmp
29
+ #else
30
+ # tags.collect! { |v| v.to_s }
31
+ #end
28
32
  tags
29
33
  end
30
34
 
@@ -38,6 +42,9 @@ module Selectable
38
42
  #
39
43
  # undefined method `>=' for nil:NilClass
40
44
  #
45
+ # It also means you need be aware of the types
46
+ # of objects you are storing as values. If you
47
+ # store a Symbol, you must send a Symbol here.
41
48
  def filter(*tags)
42
49
  tags = Selectable.normalize tags
43
50
  # select returns an Array. We want a Selectable.
@@ -22,10 +22,6 @@ tryouts "Selectable" do
22
22
  base.filter(:even => true)
23
23
  end
24
24
 
25
- drill "[] and filter are the same", true do
26
- base.filter(:even => false) == base.filter(:even => false)
27
- end
28
-
29
25
  dream :class, SelectableArray
30
26
  dream :object_id, base.object_id
31
27
  dream :size, 5
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: benelux
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.1
4
+ version: 0.4.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Delano Mandelbaum