From 4ab707e60bda209e4b56aefbf395d923fa9705c9 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Tue, 5 Jul 2016 09:56:14 +0530 Subject: [PATCH] EPUB Input: Speed up reading of the book spine from the OPF file for books with a very large number of entries in the spine Converts an O(n^2) algorithm to O(n) --- src/calibre/ebooks/metadata/opf2.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/calibre/ebooks/metadata/opf2.py b/src/calibre/ebooks/metadata/opf2.py index 674ce387e5..2ee4d556e7 100644 --- a/src/calibre/ebooks/metadata/opf2.py +++ b/src/calibre/ebooks/metadata/opf2.py @@ -301,10 +301,11 @@ class Spine(ResourceCollection): # {{{ def from_opf_spine_element(itemrefs, manifest): s = Spine(manifest) seen = set() + path_map = {i.id:i.path for i in s.manifest} for itemref in itemrefs: idref = itemref.get('idref', None) if idref is not None: - path = s.manifest.path_for_id(idref) + path = path_map.get(idref) if path and path not in seen: r = Spine.Item(lambda x:idref, path, is_path=True) r.is_linear = itemref.get('linear', 'yes') == 'yes'