Skip to content

Commit 6f5aeab

Browse files
authored
removed redundant memory allocation
1 parent d27119a commit 6f5aeab

1 file changed

Lines changed: 0 additions & 11 deletions

File tree

DynamicArray/DynamicArray.cpp

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -177,10 +177,6 @@ try {
177177
// must be: 0 <= (nPosition * sizeof type) <= (size before operation)
178178
if (nPosition < 0) return 0;
179179
if ((nPosition * da.get_sizeof_type()) > (int)da.darray.size()) return 0;
180-
181-
// make sure enough memory is allocated for the entire push back operation
182-
if (da.darray.capacity() < (da.darray.size() + (numElements * da.get_sizeof_type())))
183-
da.darray.reserve(da.darray.size() + (numElements * da.get_sizeof_type()));
184180

185181
//// insert all bytes at the same time
186182
v_char::iterator it = da.darray.begin();
@@ -231,17 +227,10 @@ int da_erase(int handle, int nPosition, int numElements)
231227
if (nEnd < 0) return 0;
232228
if ((nEnd * da.get_sizeof_type()) > (int)da.darray.size()) return 0;
233229

234-
235-
// make sure enough memory is allocated for the entire push back operation
236-
if (da.darray.capacity() < (da.darray.size() + (numElements * da.get_sizeof_type())))
237-
da.darray.reserve(da.darray.size() + (numElements * da.get_sizeof_type()));
238-
239230
v_char::iterator it = da.darray.begin();
240231
it += nPosition * da.get_sizeof_type();
241232
da.darray.erase(it, it + (numElements * da.get_sizeof_type()));
242233

243-
//da.darray.insert(it, (char*)pElement, (char*)pElement + (numElements * da.get_sizeof_type()));
244-
245234
return (int)(da.darray.size() / da.get_sizeof_type());
246235

247236
}

0 commit comments

Comments
 (0)