Skip to content

Commit

Permalink
updated v_array::erase() and delete_v to properly destroy contained e…
Browse files Browse the repository at this point in the history
…lements; removed redundant invocations of same in feature_group.h
  • Loading branch information
danmelamed committed Aug 18, 2016
1 parent 77cb357 commit db1b15c
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 8 deletions.
1 change: 1 addition & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ John Langford <[email protected]>
Bharath Krishnan
Brian Muller
Chris Quirk
Dan Melamed
Daniel Erenrich
Daniel Hsu
Doug Shore
Expand Down
3 changes: 0 additions & 3 deletions vowpalwabbit/feature_group.h
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,6 @@ struct features {
sum_feat_sq = 0.f;
values.erase();
indicies.erase();
free_space_names(0);
space_names.erase();
}

Expand Down Expand Up @@ -288,7 +287,6 @@ struct features {
{
values.delete_v();
indicies.delete_v();
free_space_names(0);
space_names.delete_v();
}
void push_back(feature_value v, feature_index i)
Expand Down Expand Up @@ -325,7 +323,6 @@ struct features {
void deep_copy_from(const features& src)
{ copy_array(values, src.values);
copy_array(indicies, src.indicies);
free_space_names(0);
copy_array_no_memcpy(space_names, src.space_names);
sum_feat_sq = src.sum_feat_sq;
}
Expand Down
15 changes: 10 additions & 5 deletions vowpalwabbit/v_array.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,14 +74,19 @@ template<class T> struct v_array

void erase()
{ if (++erase_count & erase_point)
{ resize(_end-_begin);
erase_count = 0;
}
{ resize(_end-_begin);
erase_count = 0;
}
for (T*item = _begin; item != _end; ++item)
item->~T();
_end = _begin;
}
void delete_v()
{ if (_begin != nullptr)
free(_begin);
{ if (_begin != nullptr) {
for (T*item = _begin; item != _end; ++item)
item->~T();
free(_begin);
}
_begin = _end = end_array = nullptr;
}
void push_back(const T& new_ele)
Expand Down

0 comments on commit db1b15c

Please sign in to comment.