Skip to content
This repository has been archived by the owner on Sep 12, 2024. It is now read-only.

Commit

Permalink
[MINOR]: Use shallow cloning instead of copy/deepcopy
Browse files Browse the repository at this point in the history
  • Loading branch information
amadolid committed Aug 14, 2024
1 parent 03dbf72 commit d75fc1d
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions jaclang/runtimelib/architype.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

from __future__ import annotations

from copy import deepcopy
from dataclasses import asdict, dataclass, field, is_dataclass
from enum import Enum, IntEnum
from os import getenv
Expand Down Expand Up @@ -203,6 +202,16 @@ def destroy(self) -> None:
self.state.deleted = False
ctx_src.remove(self)

def unlinked_architype(self) -> Architype | None:
"""Unlink architype."""
# this is to avoid using copy/deepcopy as it can be overriden by architypes in language level
if self.architype:
cloned = object.__new__(self.architype.__class__)
cloned.__dict__.update(self.architype.__dict__)
cloned.__dict__.pop("__jac__", None)
return cloned
return None

def unsync(self: TANCH) -> TANCH:
"""Return unsynced copy of anchor."""
unsynced = object.__new__(self.__class__)
Expand Down Expand Up @@ -312,11 +321,7 @@ def __getstate__(self) -> dict[str, object]:
"""Serialize Anchor."""
state: dict[str, object] = {"name": self.name, "id": self.id}

if self.architype:
# clone architype excluding __jac__
architype = deepcopy(self.architype, memo={id(self): self})
architype.__dict__.pop("__jac__")

if architype := self.unlinked_architype():
state.update(
{
"root": self.root,
Expand Down

0 comments on commit d75fc1d

Please sign in to comment.