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

Use emplace instead of insert/push in ObserverPool::add #242

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

frmdstryr
Copy link
Contributor

This avoids an extra xincref/xdecref on the cppy::ptr because insert & push_back do a copy.

See https://godbolt.org/z/zGvTzGahn

The *obs_free = Observer() does the same thing but I'm not sure how to cleany fix that (other than manually setting the fields).

Copy link

codecov bot commented Feb 1, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 97.67%. Comparing base (0750392) to head (c666579).
Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #242   +/-   ##
=======================================
  Coverage   97.67%   97.67%           
=======================================
  Files          24       24           
  Lines        1074     1074           
  Branches      162      162           
=======================================
  Hits         1049     1049           
  Misses         12       12           
  Partials       13       13           

@sccolbert
Copy link
Member

sccolbert commented Feb 2, 2025

For the last part, I think you can do:

obs_free->m_change_types = change_types;
obs_free->m_observer = observer;

Or you could add a method to the Observer struct to swap the fields for you. You could add a couple overloads to that method to also eliminate the other places where we manually twiddle the field.

Honestly, I can't remember why I made Observer a struct instead of class with more encapsulated behavior.

I think I would take the later approach if I were to do it again.

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