Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make set_image_count() efficient with large values. #115

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

riccardomurri
Copy link

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, calling get_image_count() (via the self.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:

  • caching the value of get_image_count() in an attribute self._image_count
  • ensuring that get_image_count() is called at most 2 times from within set_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 )

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant