Skip to content

Commit 932e0ba

Browse files
authored
fix: Change if condition typo in _get_children_of_element() (#313)
The previous `if` condition was inefficient and should have been written with an `and` This resulted in a performance gap. cProfile timing of `export_hocr_string()` on the same document Before ``` 143598720 function calls (129111346 primitive calls) in 44.487 seconds ``` After ``` 97883150 function calls (88084552 primitive calls) in 30.235 seconds ``` Fixes #312 🦕
1 parent d6f7de1 commit 932e0ba

File tree

1 file changed

+5
-3
lines changed
  • packages/google-cloud-documentai-toolbox/google/cloud/documentai_toolbox/wrappers

1 file changed

+5
-3
lines changed

packages/google-cloud-documentai-toolbox/google/cloud/documentai_toolbox/wrappers/page.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -359,9 +359,11 @@ def _get_children_of_element(
359359
return [
360360
child
361361
for child in children
362-
if child.documentai_object.layout.text_anchor.text_segments[0].start_index
363-
>= start_index
364-
if child.documentai_object.layout.text_anchor.text_segments[0].end_index
362+
if start_index
363+
<= child.documentai_object.layout.text_anchor.text_segments[0].start_index
364+
< end_index
365+
and start_index
366+
< child.documentai_object.layout.text_anchor.text_segments[0].end_index
365367
<= end_index
366368
]
367369

0 commit comments

Comments
 (0)