mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Small performance optimization
This commit is contained in:
parent
a937ccdcdf
commit
a006aed4f1
@ -58,14 +58,12 @@ def file_data(container):
|
|||||||
|
|
||||||
Image = namedtuple('Image', 'name mime_type usage size basename id width height')
|
Image = namedtuple('Image', 'name mime_type usage size basename id width height')
|
||||||
|
|
||||||
L = namedtuple('Location', 'name line_number text_on_line word_on_line character_offset')
|
LinkLocation = namedtuple('LinkLocation', 'name line_number text_on_line')
|
||||||
def Location(name, line_number=None, text_on_line=None, word_on_line=None, character_offset=None):
|
|
||||||
return L(name, line_number, text_on_line, word_on_line, character_offset)
|
|
||||||
|
|
||||||
def sort_locations(container, locations):
|
def sort_locations(container, locations):
|
||||||
nmap = {n:i for i, (n, l) in enumerate(container.spine_names)}
|
nmap = {n:i for i, (n, l) in enumerate(container.spine_names)}
|
||||||
def sort_key(l):
|
def sort_key(l):
|
||||||
return (nmap.get(l.name, 100000), numeric_sort_key(l.name), l.line_number, l.character_offset)
|
return (nmap.get(l.name, len(nmap)), numeric_sort_key(l.name), l.line_number)
|
||||||
return sorted(locations, key=sort_key)
|
return sorted(locations, key=sort_key)
|
||||||
|
|
||||||
def link_data(container):
|
def link_data(container):
|
||||||
@ -78,7 +76,7 @@ def link_data(container):
|
|||||||
if target and container.exists(target):
|
if target and container.exists(target):
|
||||||
mt = container.mime_map.get(target)
|
mt = container.mime_map.get(target)
|
||||||
if mt and mt.startswith('image/'):
|
if mt and mt.startswith('image/'):
|
||||||
image_usage[target].add(Location(name, line_number, text_on_line=href))
|
image_usage[target].add(LinkLocation(name, line_number, href))
|
||||||
|
|
||||||
image_data = []
|
image_data = []
|
||||||
for name, mt in container.mime_map.iteritems():
|
for name, mt in container.mime_map.iteritems():
|
||||||
|
Loading…
x
Reference in New Issue
Block a user