11/*
2- * Copyright 2018-2020 , Intel Corporation
2+ * Copyright 2018-2021 , Intel Corporation
33 *
44 * Redistribution and use in source and binary forms, with or without
55 * modification, are permitted provided that the following conditions
@@ -672,7 +672,7 @@ vector<T>::assign(size_type count, const_reference value)
672672 add_data_to_tx (0 , size_old);
673673
674674 std::fill_n (
675- & _data[ 0 ] ,
675+ _data. get () ,
676676 (std::min)(count,
677677 static_cast <size_type>(size_old)),
678678 value);
@@ -1604,7 +1604,7 @@ vector<T>::insert(const_iterator pos, size_type count, const value_type &value)
16041604 single_element_iterator<value_type>(&value, count));
16051605 });
16061606
1607- return iterator (& _data[ static_cast <difference_type>(idx)] );
1607+ return iterator (_data. get () + static_cast <difference_type>(idx));
16081608}
16091609
16101610/* *
@@ -1847,7 +1847,7 @@ typename vector<T>::iterator
18471847vector<T>::erase(const_iterator first, const_iterator last)
18481848{
18491849 size_type idx = static_cast <size_type>(
1850- std::distance (const_iterator (& _data[ 0 ] ), first));
1850+ std::distance (const_iterator (_data. get () ), first));
18511851 size_type count = static_cast <size_type>(std::distance (first, last));
18521852
18531853 if (count == 0 )
@@ -2323,10 +2323,11 @@ vector<T>::internal_insert(size_type idx, InputIt first, InputIt last)
23232323 auto count = static_cast <size_type>(std::distance (first, last));
23242324
23252325 if (_capacity >= size () + count) {
2326- pointer dest =
2327- &_data[static_cast <difference_type>(size () + count)];
2328- pointer begin = &_data[static_cast <difference_type>(idx)];
2329- pointer end = &_data[static_cast <difference_type>(size ())];
2326+ pointer dest = _data.get () +
2327+ static_cast <difference_type>(size () + count);
2328+ pointer begin = _data.get () + static_cast <difference_type>(idx);
2329+ pointer end =
2330+ _data.get () + static_cast <difference_type>(size ());
23302331
23312332 add_data_to_tx (idx, size () - idx + count);
23322333
@@ -2344,9 +2345,11 @@ vector<T>::internal_insert(size_type idx, InputIt first, InputIt last)
23442345
23452346 auto old_data = _data;
23462347 auto old_size = _size;
2347- pointer old_begin = &_data[0 ];
2348- pointer old_mid = &_data[static_cast <difference_type>(idx)];
2349- pointer old_end = &_data[static_cast <difference_type>(size ())];
2348+ pointer old_begin = _data.get ();
2349+ pointer old_mid =
2350+ _data.get () + static_cast <difference_type>(idx);
2351+ pointer old_end =
2352+ _data.get () + static_cast <difference_type>(size ());
23502353
23512354 _data = nullptr ;
23522355 _size = _capacity = 0 ;
@@ -2379,7 +2382,8 @@ vector<T>::internal_insert(size_type idx, InputIt first, InputIt last)
23792382 * Private helper function. Must be called during transaction. Allocates new
23802383 * memory for capacity_new number of elements and copies or moves old elements
23812384 * to new memory area. If the current size is greater than capacity_new, the
2382- * container is reduced to its first capacity_new elements.
2385+ * container is reduced to its first capacity_new elements. If was never
2386+ * allocated behaves as an alloc call.
23832387 *
23842388 * param[in] capacity_new new capacity.
23852389 *
@@ -2398,6 +2402,13 @@ vector<T>::realloc(size_type capacity_new)
23982402{
23992403 assert (pmemobj_tx_stage () == TX_STAGE_WORK);
24002404
2405+ /*
2406+ * If _data == nullptr this object has never allocated any memory
2407+ * so we need to behave as alloc instead.
2408+ */
2409+ if (_data == nullptr )
2410+ return alloc (capacity_new);
2411+
24012412 /*
24022413 * XXX: future optimization: we don't have to snapshot data
24032414 * which we will not overwrite
@@ -2406,7 +2417,7 @@ vector<T>::realloc(size_type capacity_new)
24062417
24072418 auto old_data = _data;
24082419 auto old_size = _size;
2409- pointer old_begin = & _data[ 0 ] ;
2420+ pointer old_begin = _data. get () ;
24102421 pointer old_end = capacity_new < _size
24112422 ? &_data[static_cast <difference_type>(capacity_new)]
24122423 : &_data[static_cast <difference_type>(size ())];
0 commit comments