Skip to content

Commit

Permalink
Improve replace on HyObject so it does less work
Browse files Browse the repository at this point in the history
Calling `replace` can trigger a call to `replace_hy_obj`, which will
try to also wrap values inside a `HyObject`.

However, this means when we try to recusively replace inside a nested
object, like a `HyList`, we should try and capture these new wrapped
objects.

Hy still works if we don't, but it results in the object getting
rewrapped multiple times during a compile.

Closes hylang#1519
  • Loading branch information
vodik committed Mar 25, 2018
1 parent f57463c commit fe61a5f
Showing 1 changed file with 3 additions and 6 deletions.
9 changes: 3 additions & 6 deletions hy/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,11 +226,8 @@ class HyList(HyObject, list):
"""

def replace(self, other):
for x in self:
replace_hy_obj(x, other)

HyObject.replace(self, other)
return self
self[:] = [replace_hy_obj(x, other) for x in self]
return HyObject.replace(self, other)

def __add__(self, other):
return self.__class__(super(HyList, self).__add__(other))
Expand Down Expand Up @@ -391,7 +388,7 @@ def replace(self, other):
if self.cdr is not None:
replace_hy_obj(self.cdr, other)

HyObject.replace(self, other)
return HyObject.replace(self, other)

def __repr__(self):
if PRETTY:
Expand Down

0 comments on commit fe61a5f

Please sign in to comment.