From d5751aad89b8f4efaee170b7712603bc9ded7845 Mon Sep 17 00:00:00 2001 From: Nicolas Delaby <nicolas@nexedi.com> Date: Tue, 23 Nov 2010 10:24:14 +0000 Subject: [PATCH] Small optimization, there no need to calculate len of dictionaries or list: bool([]) == bool({}) == False git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@40522 20353a03-c40f-0410-a6d1-a30d3c3de9de --- product/Formulator/Widget.py | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/product/Formulator/Widget.py b/product/Formulator/Widget.py index 2b4c9cdce7..34ae5b77b0 100644 --- a/product/Formulator/Widget.py +++ b/product/Formulator/Widget.py @@ -260,23 +260,27 @@ class Widget: value = value.decode('utf-8') draw_frame_tag_name = '{%s}%s' % (DRAW_URI, 'frame') draw_frame_node = Element(draw_frame_tag_name, nsmap=NSMAP) - if len(attr_dict.get(draw_frame_tag_name, {})) > 0: - draw_frame_node.attrib.update(attr_dict.get(draw_frame_tag_name, {}).pop(0)) + draw_frame_attribute_dict = attr_dict.get(draw_frame_tag_name) + if draw_frame_attribute_dict: + draw_frame_node.attrib.update(draw_frame_attribute_dict) draw_tag_name = '{%s}%s' % (DRAW_URI, 'text-box') draw_node = Element(draw_tag_name, nsmap=NSMAP) - if len(attr_dict.get(draw_tag_name, {})) > 0: - draw_node.attrib.update(attr_dict.get(draw_tag_name, {}).pop(0)) + fraw_tag_attribute_dict = attr_dict.get(draw_tag_name) + if fraw_tag_attribute_dict: + draw_node.attrib.update(fraw_tag_attribute_dict) text_p_tag_name = '{%s}%s' % (TEXT_URI, 'p') text_p_node = Element(text_p_tag_name, nsmap=NSMAP) - if len(attr_dict.get(text_p_tag_name, {})) > 0: - text_p_node.attrib.update(attr_dict.get(text_p_tag_name, {}).pop(0)) + text_p_attribute_dict = attr_dict.get(text_p_tag_name) + if text_p_attribute_dict: + text_p_node.attrib.update(text_p_attribute_dict) text_span_tag_name = '{%s}%s' % (TEXT_URI, 'span') text_span_node = Element(text_span_tag_name, nsmap=NSMAP) - if len(attr_dict.get(text_span_tag_name, {})) > 0: - text_span_node.attrib.update(attr_dict.get(text_span_tag_name, {}).pop(0)) + text_span_attribute_dict = attr_dict.get(text_span_tag_name) + if text_span_attribute_dict: + text_span_node.attrib.update(text_span_attribute_dict) text_p_node.append(text_span_node) draw_node.append(text_p_node) -- GitLab