@@ -607,18 +607,18 @@ template <typename T>
607607typename KeyframeContainer<T>::elem_ptr
608608KeyframeContainer<T>::sync(const KeyframeContainer<T> &other,
609609 const time::time_t &start) {
610- // Delete elements after start time
610+ // Delete elements from this container after start time
611611 elem_ptr at = this ->last_before (start, this ->container .size ());
612612 at = this ->erase_after (at);
613613
614- auto at_other = 1 ; // always skip the first element (because it's the default value)
614+ // Find the last element before the start time in the other container
615+ elem_ptr at_other = other.last_before (start, other.size ());
616+ ++at_other; // move one element forward so that at_other.time() >= start
615617
616618 // Copy all elements from other with time >= start
617- for (size_t i = at_other; i < other.size (); i++) {
618- if (other.get (i).time () >= start) {
619- at = this ->insert_after (other.get (i), at);
620- }
621- }
619+ this ->container .insert (this ->container .end (),
620+ other.container .begin () + at_other,
621+ other.container .end ());
622622
623623 return this ->container .size ();
624624}
@@ -634,13 +634,14 @@ KeyframeContainer<T>::sync(const KeyframeContainer<O> &other,
634634 elem_ptr at = this ->last_before (start, this ->container .size ());
635635 at = this ->erase_after (at);
636636
637- auto at_other = 1 ; // always skip the first element (because it's the default value)
637+ // Find the last element before the start time in the other container
638+ elem_ptr at_other = other.last_before (start, other.size ());
639+ ++at_other; // move one element forward so that at_other.time() >= start
638640
639641 // Copy all elements from other with time >= start
640642 for (size_t i = at_other; i < other.size (); i++) {
641- if (other.get (i).time () >= start) {
642- at = this ->insert_after (keyframe_t (other.get (i).time (), converter (other.get (i).val ())), at);
643- }
643+ auto &elem = other.get (i);
644+ this ->container .emplace_back (elem.time (), converter (elem.val ()));
644645 }
645646
646647 return this ->container .size ();
0 commit comments