Make set_image_count()
efficient with large values.
#115
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The current implementation of
get_image_count()
scans the XML to find all image elements; on the other hand,set_image_count()
adds those elements 1 by 1, callingget_image_count()
(via theself.image_count
property) every time. This results in a quadratic complexity algorithm which gets really slow when the number of images number over a few 10's of thousands.This PR fixes the issue by:
get_image_count()
in an attributeself._image_count
get_image_count()
is called at most 2 times from withinset_image_count()
The resulting behavior is that
set_image_count()
runs in linear time for every value.(Issue reported by --and patch co-developed with-- @scottberry )