Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[PREVIEW] deprecate last and pop, implement insert, erase, capacity #1

Open
wants to merge 3 commits into
base: parser_string_view
Choose a base branch
from

Conversation

peterychang
Copy link
Owner

usage of back() and pop_back() gives a minor performance boost over last() and pop() (mostly because pop_back() doesn't return anything).

Slight losses in performance can be see in some cases, notably pop_back() calling the destructor and back() requiring a pointer dereference and not being able to RVO when copying in some cases; overall has better performance characteristics than the old interface. The old interface is maintained for compatibility.

Additionally added 3 new functions from the standard interface (with some minor differences). Replaced relevant places with these function calls.

capacity()
insert()
erase()

@peterychang
Copy link
Owner Author

@jackgerrits
@lokitoth

n2_i = (int)i;
memmove(&ec.indices[n2_i], &ec.indices[n2_i + 1], sizeof(unsigned char) * (ec.indices.size() - n2_i - 1));
ec.indices.decr();
ec.indices.erase(n2_i);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It just works? It's that easy?!

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see its a member function, still great!

@@ -103,7 +103,7 @@ void io_buf::buf_write(char*& pointer, size_t n)
flush();
else // Array is short, so increase size.
{
space.resize(2 * (space.end_array - space.begin()));
space.resize(2 * space.capacity());

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, thankyou!

@@ -1080,7 +1080,7 @@ void allowed_actions_to_label(search_private& priv, size_t ec_cnt, const action*
template <class T>
void ensure_size(v_array<T>& A, size_t sz)
{
if ((size_t)(A.end_array - A.begin()) < sz)
if (A.capacity() < sz)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎉

vowpalwabbit/v_array.h Outdated Show resolved Hide resolved
Copy link

@jackgerrits jackgerrits left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants