1
1
mirror of https://github.com/Kozea/WeasyPrint.git synced 2024-10-05 08:27:22 +03:00

Don't copy style when removing decorations if there's no need to

It saves a lot of memory for very long paragraphs with no decoration style.
This commit is contained in:
Guillaume Ayoub 2019-07-11 14:48:58 +02:00
parent 76c3a47607
commit 005d9a3c9f

View File

@ -316,11 +316,15 @@ class ParentBox(Box):
def _remove_decoration(self, start, end): def _remove_decoration(self, start, end):
if start or end: if start or end:
old_style = self.style
self.style = self.style.copy() self.style = self.style.copy()
if start: if start:
self._reset_spacing('top') self._reset_spacing('top')
if end: if end:
self._reset_spacing('bottom') self._reset_spacing('bottom')
if (start or end) and old_style == self.style:
# Don't copy style if there's no need to, save some memory
self.style = old_style
def copy_with_children(self, new_children, is_start=True, is_end=True): def copy_with_children(self, new_children, is_start=True, is_end=True):
"""Create a new equivalent box with given ``new_children``.""" """Create a new equivalent box with given ``new_children``."""