From d576d4de77ba815634bfba8246e0826ac8572d2c Mon Sep 17 00:00:00 2001 From: Samuel Kaessner Date: Mon, 16 Nov 2020 12:45:26 -0700 Subject: [PATCH] Update pdfquery.py Replacing `all(...` with simple ands cuts time to 1/3 of what it took before. Found this after profiling on a pdf that required ~32m of these comparisons --- pdfquery/pdfquery.py | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/pdfquery/pdfquery.py b/pdfquery/pdfquery.py index 1c622e3..da90815 100644 --- a/pdfquery/pdfquery.py +++ b/pdfquery/pdfquery.py @@ -62,13 +62,7 @@ def _append_sorted(root, el, comparator): def _box_in_box(el, child): """ Return True if child is contained within el. """ - return all([ - float(el.get('x0')) <= float(child.get('x0')), - float(el.get('x1')) >= float(child.get('x1')), - float(el.get('y0')) <= float(child.get('y0')), - float(el.get('y1')) >= float(child.get('y1')), - ]) - + return (float(el.get('x0')) <= float(child.get('x0'))) and (float(el.get('x1')) >= float(child.get('x1'))) and (float(el.get('y0')) <= float(child.get('y0'))) and (float(el.get('y1')) >= float(child.get('y1'))) _comp_bbox_keys_required = set(['x0', 'x1', 'y0', 'y1']) def _comp_bbox(el, el2):