Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

improve Scissor::Chunk#fill

  • Loading branch information...
commit 00a64c1df5d9abeb180c96f4afd0df8510a10f81 1 parent 6997d03
youpy authored

Showing 1 changed file with 5 additions and 18 deletions. Show diff stats Hide diff stats

  1. +5 18 lib/scissor/chunk.rb
23 lib/scissor/chunk.rb
@@ -109,9 +109,8 @@ def +(other)
109 109 def loop(count)
110 110 orig_fragments = @fragments.clone
111 111 new_instance = Scissor()
112   - new_instance.add_fragments(orig_fragments)
113 112
114   - (count - 1).times do
  113 + count.times do
115 114 new_instance.add_fragments(orig_fragments)
116 115 end
117 116
@@ -134,26 +133,14 @@ def split(count)
134 133 alias / split
135 134
136 135 def fill(filled_duration)
137   - if @fragments.empty?
  136 + if duration.zero?
138 137 raise EmptyFragment
139 138 end
140 139
141   - remain = filled_duration
142   - new_instance = self.class.new
143   -
144   - while !remain.zero? && filled_duration > new_instance.duration
145   - if remain < duration
146   - added = slice(0, remain)
147   - else
148   - added = self
149   - end
  140 + loop_count = (filled_duration / duration).to_i
  141 + remain = filled_duration % duration
150 142
151   - new_instance += added
152   - remain -= added.duration
153   - end
154   -
155   -
156   - new_instance
  143 + loop(loop_count) + slice(0, remain)
157 144 end
158 145
159 146 def replace(start, length, replaced)

0 comments on commit 00a64c1

Please sign in to comment.
Something went wrong with that request. Please try again.