fix process#alive? to not raise on no such file
[god.git] / lib / god / timeline.rb
blob12c1904160a79bd9b89bd8bfb5115e86a9401827
1 module God
2     
3     class Timeline < Array
4       def initialize(max_size)
5         super()
6         @max_size = max_size
7       end
8       
9       # Push a value onto the Timeline
10       # 
11       # Implementation explanation:
12       # A performance optimization appears here to speed up the push time.
13       # In essence, the code does this:
14       #
15       #   def push(val)
16       #     super(val)
17       #     shift if size > @max_size
18       #   end
19       #
20       # But that's super slow due to the shift, so we resort to reverse! and pop
21       # which gives us a 2x speedup with 100 elements and a 6x speedup with 1000
22       def push(val)
23         if (size + 1) > @max_size
24           reverse!
25           pop
26           reverse!
27         end
28         super(val)
29       end
30       
31       def <<(val)
32         push(val)
33       end
34     end
35     
36 end