• R/O
  • SSH
  • HTTPS

eirrepo: Commit


Commit MetaInfo

Revision158 (tree)
Time2018-12-02 15:26:18
Authorquiret

Log Message

- fixed some critical bugs with the insertion algorithm of eir::Vector

Change Summary

Incremental Difference

--- common/sdk/Vector.h (revision 157)
+++ common/sdk/Vector.h (revision 158)
@@ -404,7 +404,7 @@
404404 std::is_nothrow_move_assignable <structType>::value
405405 );
406406
407- bool hasOldBuffer = false;
407+ bool hasTakenOldBuffer = false;
408408
409409 // First try resizing the old buffer.
410410 if constexpr ( can_safely_move_data )
@@ -415,7 +415,7 @@
415415
416416 if ( couldGrow )
417417 {
418- hasOldBuffer = true;
418+ hasTakenOldBuffer = true;
419419
420420 use_data = oldData;
421421 goto hasAcquiredDataPointer;
@@ -471,7 +471,7 @@
471471 }
472472 }
473473
474- hasOldBuffer = false;
474+ hasTakenOldBuffer = false;
475475
476476 use_data = new_data;
477477 goto hasAcquiredDataPointer;
@@ -536,7 +536,7 @@
536536
537537 structType *move_from = ( oldData + src_move_idx );
538538
539- if ( hasOldBuffer == true && dst_move_idx >= oldCount )
539+ if ( hasTakenOldBuffer == false || dst_move_idx >= oldCount )
540540 {
541541 new ( use_data + dst_move_idx ) structType( std::move( *move_from ) );
542542 }
@@ -599,12 +599,12 @@
599599 // Here we want to allow a template to take over.
600600 size_t already_constr_count = 0;
601601
602- if ( hasOldBuffer && insertPos < oldCount )
602+ if ( hasTakenOldBuffer && insertPos < oldCount )
603603 {
604604 already_constr_count = ( oldCount - insertPos );
605605 }
606606
607- cb( use_data + insertPos, already_constr_count, hasOldBuffer );
607+ cb( use_data + insertPos, already_constr_count, hasTakenOldBuffer );
608608
609609 // Success! Update the array meta-data.
610610 this->data.data_entries = use_data;
@@ -611,7 +611,7 @@
611611 this->data.data_count = reqCount;
612612
613613 // Delete any old pointers with their data.
614- if ( hasOldBuffer == false )
614+ if ( hasTakenOldBuffer == false && oldData != nullptr )
615615 {
616616 for ( size_t n = 0; n < oldCount; n++ )
617617 {
@@ -649,7 +649,7 @@
649649 oldData[ src_move_idx ] = std::move( *move_from );
650650
651651 // Safe to delete because end node?
652- if ( hasOldBuffer == false || dst_move_idx >= oldCount )
652+ if ( hasTakenOldBuffer == false || dst_move_idx >= oldCount )
653653 {
654654 move_from->~structType();
655655 }
@@ -682,7 +682,7 @@
682682 // Destroy all the newly spawned empty copies.
683683 for ( size_t spawn_idx = oldCount; spawn_idx < insertPos; spawn_idx++ )
684684 {
685- oldData[ spawn_idx ].~structType();
685+ use_data[ spawn_idx ].~structType();
686686 }
687687 }
688688
@@ -691,7 +691,7 @@
691691 }
692692 catch( ... )
693693 {
694- if ( hasOldBuffer )
694+ if ( hasTakenOldBuffer )
695695 {
696696 // Shrink back the memory.
697697 // This operation cannot fail.
Show on old repository browser