Skip to content

Efficiency: remove unnecessary copy operation - #288

Open
MetRonnie wants to merge 1 commit into
metomi:masterfrom
MetRonnie:optimise
Open

Efficiency: remove unnecessary copy operation#288
MetRonnie wants to merge 1 commit into
metomi:masterfrom
MetRonnie:optimise

Conversation

@MetRonnie

Copy link
Copy Markdown
Contributor

Alternative to #285

@MetRonnie MetRonnie added this to the 3.2.0 milestone Jun 29, 2026
@MetRonnie
MetRonnie requested a review from oliver-sanders June 29, 2026 15:30
@MetRonnie MetRonnie self-assigned this Jun 29, 2026
for attr in self.__slots__:
value = getattr(self, attr, None)
if callable(getattr(value, "_copy", None)):
value = value._copy()

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I am convinced this copy was unnecessary. Note it's the time zone that was being copied. The only uses of this method:

  • In the comparison function, where no references to the time zone are created
  • In def get_timepoint_properties_from_seconds_since_unix_epoch(), where a local reference to the time zone is created, but not mutated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think you are right.

The only mutable property returned is the time zone. This is a TimeZone(Duration) object which is __hash__able. It provides no methods that would mutate the object, you would have to meddle with a _ prefixed variable to mess it up.

Seems reasonable.

@oliver-sanders oliver-sanders left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This looks good to me, but we don't actually have any tests for this method.

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