mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
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)
This commit is contained in:
parent
415ebb7a6c
commit
4ab707e60b
@ -301,10 +301,11 @@ class Spine(ResourceCollection): # {{{
|
|||||||
def from_opf_spine_element(itemrefs, manifest):
|
def from_opf_spine_element(itemrefs, manifest):
|
||||||
s = Spine(manifest)
|
s = Spine(manifest)
|
||||||
seen = set()
|
seen = set()
|
||||||
|
path_map = {i.id:i.path for i in s.manifest}
|
||||||
for itemref in itemrefs:
|
for itemref in itemrefs:
|
||||||
idref = itemref.get('idref', None)
|
idref = itemref.get('idref', None)
|
||||||
if idref is not 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:
|
if path and path not in seen:
|
||||||
r = Spine.Item(lambda x:idref, path, is_path=True)
|
r = Spine.Item(lambda x:idref, path, is_path=True)
|
||||||
r.is_linear = itemref.get('linear', 'yes') == 'yes'
|
r.is_linear = itemref.get('linear', 'yes') == 'yes'
|
||||||
|
Loading…
x
Reference in New Issue
Block a user