From 005d9a3c9fa9980ce113013e30b77652307122d6 Mon Sep 17 00:00:00 2001 From: Guillaume Ayoub Date: Thu, 11 Jul 2019 14:48:58 +0200 Subject: [PATCH] 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. --- weasyprint/formatting_structure/boxes.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/weasyprint/formatting_structure/boxes.py b/weasyprint/formatting_structure/boxes.py index 559eeda9..fd4a2c74 100644 --- a/weasyprint/formatting_structure/boxes.py +++ b/weasyprint/formatting_structure/boxes.py @@ -316,11 +316,15 @@ class ParentBox(Box): def _remove_decoration(self, start, end): if start or end: + old_style = self.style self.style = self.style.copy() if start: self._reset_spacing('top') if end: 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): """Create a new equivalent box with given ``new_children``."""