Skip to content
Browse files

improve Scissor::Chunk#fill

  • Loading branch information...
1 parent 6997d03 commit 00a64c1df5d9abeb180c96f4afd0df8510a10f81 @youpy committed Dec 2, 2011
Showing with 5 additions and 18 deletions.
  1. +5 −18 lib/scissor/chunk.rb
View
23 lib/scissor/chunk.rb
@@ -109,9 +109,8 @@ def +(other)
def loop(count)
orig_fragments = @fragments.clone
new_instance = Scissor()
- new_instance.add_fragments(orig_fragments)
- (count - 1).times do
+ count.times do
new_instance.add_fragments(orig_fragments)
end
@@ -134,26 +133,14 @@ def split(count)
alias / split
def fill(filled_duration)
- if @fragments.empty?
+ if duration.zero?
raise EmptyFragment
end
- remain = filled_duration
- new_instance = self.class.new
-
- while !remain.zero? && filled_duration > new_instance.duration
- if remain < duration
- added = slice(0, remain)
- else
- added = self
- end
+ loop_count = (filled_duration / duration).to_i
+ remain = filled_duration % duration
- new_instance += added
- remain -= added.duration
- end
-
-
- new_instance
+ loop(loop_count) + slice(0, remain)
end
def replace(start, length, replaced)

0 comments on commit 00a64c1

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