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 #1519
  • Loading branch information
vodik committed Mar 25, 2018
1 parent f57463c commit 70a414c
Showing 1 changed file with 5 additions and 8 deletions.
13 changes: 5 additions & 8 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 @@ -387,11 +384,11 @@ def __iter__(self):

def replace(self, other):
if self.car is not None:
replace_hy_obj(self.car, other)
self.car = replace_hy_obj(self.car, other)
if self.cdr is not None:
replace_hy_obj(self.cdr, other)
self.cdr = 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 70a414c

Please sign in to comment.