-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Improve Line2D and MarkerStyle instantiation #6694
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
Improve Line2D and MarkerStyle instantiation #6694
Conversation
@@ -229,7 +230,9 @@ def set_fillstyle(self, fillstyle): | |||
raise ValueError("Unrecognized fillstyle %s" | |||
% ' '.join(self.fillstyles)) | |||
self._fillstyle = fillstyle | |||
self._recache() | |||
# do not call _recache() if marker is not yet set up | |||
if self._marker is not None: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I do not like this much. Otherwise we can extract body of set_fillstyle
without _recache()
call to an internal method and call it from __init__
and set_fillstyle
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe add a _defer_recache=False
kwarg to both set_marker
and set_fillstyle
? That way in __init__
you can prevent it from running.
A more invasive (but maybe better?) solution could be to use the stale/invalid pattern and then in all of the get_*
methods check if it is stale and if so recache it.
Because `set_marker` calls it by itself
# The _recache() is called in both set_fillstyle() and set_marker() | ||
# methods that's why here we have to have either marker or fillstyle | ||
# preinitialized before setting other. | ||
self._marker = None |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is probably better from a readability stand point to initialize all of the state here, rather than relying on a call to _recache
to set it all up.
1ba7be6
to
486ce4d
Compare
I have pushed alternative solution for double What about moving out initialization from |
I suspect that not all of the |
Yes, I can confirm this as I have already tried it. |
This reduces
MarkerStyle._recache()
calls from 4 to 1 inLine2D
instantiation