mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Micro-optimization
This commit is contained in:
parent
e25d26a628
commit
f6087f7929
@ -571,6 +571,16 @@ def select_nth_last_of_type(cache, function, elem):
|
|||||||
# Pseudo elements {{{
|
# Pseudo elements {{{
|
||||||
|
|
||||||
|
|
||||||
|
def pseudo_func(f):
|
||||||
|
f.is_pseudo = True
|
||||||
|
return f
|
||||||
|
|
||||||
|
|
||||||
|
@pseudo_func
|
||||||
|
def allow_all(cache, item):
|
||||||
|
return True
|
||||||
|
|
||||||
|
|
||||||
def select_pseudo(cache, pseudo):
|
def select_pseudo(cache, pseudo):
|
||||||
try:
|
try:
|
||||||
func = cache.dispatch_map[pseudo.ident.replace('-', '_')]
|
func = cache.dispatch_map[pseudo.ident.replace('-', '_')]
|
||||||
@ -580,9 +590,7 @@ def select_pseudo(cache, pseudo):
|
|||||||
return
|
return
|
||||||
|
|
||||||
if pseudo.ident in cache.ignore_inappropriate_pseudo_classes:
|
if pseudo.ident in cache.ignore_inappropriate_pseudo_classes:
|
||||||
def func(cache, item):
|
func = allow_all
|
||||||
return True
|
|
||||||
func.is_pseudo = True
|
|
||||||
else:
|
else:
|
||||||
raise ExpressionError(
|
raise ExpressionError(
|
||||||
"The pseudo-class :%s is not supported" % pseudo.ident)
|
"The pseudo-class :%s is not supported" % pseudo.ident)
|
||||||
@ -598,6 +606,7 @@ def select_pseudo(cache, pseudo):
|
|||||||
yield item
|
yield item
|
||||||
|
|
||||||
|
|
||||||
|
@pseudo_func
|
||||||
def select_first_child(cache, elem):
|
def select_first_child(cache, elem):
|
||||||
try:
|
try:
|
||||||
return cache.sibling_count(elem) == 0
|
return cache.sibling_count(elem) == 0
|
||||||
@ -605,9 +614,7 @@ def select_first_child(cache, elem):
|
|||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
select_first_child.is_pseudo = True
|
@pseudo_func
|
||||||
|
|
||||||
|
|
||||||
def select_last_child(cache, elem):
|
def select_last_child(cache, elem):
|
||||||
try:
|
try:
|
||||||
return cache.sibling_count(elem, before=False) == 0
|
return cache.sibling_count(elem, before=False) == 0
|
||||||
@ -615,9 +622,7 @@ def select_last_child(cache, elem):
|
|||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
select_last_child.is_pseudo = True
|
@pseudo_func
|
||||||
|
|
||||||
|
|
||||||
def select_only_child(cache, elem):
|
def select_only_child(cache, elem):
|
||||||
try:
|
try:
|
||||||
return cache.all_sibling_count(elem) == 0
|
return cache.all_sibling_count(elem) == 0
|
||||||
@ -625,9 +630,7 @@ def select_only_child(cache, elem):
|
|||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
select_only_child.is_pseudo = True
|
@pseudo_func
|
||||||
|
|
||||||
|
|
||||||
def select_first_of_type(cache, elem):
|
def select_first_of_type(cache, elem):
|
||||||
try:
|
try:
|
||||||
return cache.sibling_count(elem, same_type=True) == 0
|
return cache.sibling_count(elem, same_type=True) == 0
|
||||||
@ -635,9 +638,7 @@ def select_first_of_type(cache, elem):
|
|||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
select_first_of_type.is_pseudo = True
|
@pseudo_func
|
||||||
|
|
||||||
|
|
||||||
def select_last_of_type(cache, elem):
|
def select_last_of_type(cache, elem):
|
||||||
try:
|
try:
|
||||||
return cache.sibling_count(elem, before=False, same_type=True) == 0
|
return cache.sibling_count(elem, before=False, same_type=True) == 0
|
||||||
@ -645,9 +646,7 @@ def select_last_of_type(cache, elem):
|
|||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
select_last_of_type.is_pseudo = True
|
@pseudo_func
|
||||||
|
|
||||||
|
|
||||||
def select_only_of_type(cache, elem):
|
def select_only_of_type(cache, elem):
|
||||||
try:
|
try:
|
||||||
return cache.all_sibling_count(elem, same_type=True) == 0
|
return cache.all_sibling_count(elem, same_type=True) == 0
|
||||||
@ -655,15 +654,11 @@ def select_only_of_type(cache, elem):
|
|||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
select_only_of_type.is_pseudo = True
|
@pseudo_func
|
||||||
|
|
||||||
|
|
||||||
def select_empty(cache, elem):
|
def select_empty(cache, elem):
|
||||||
return cache.is_empty(elem)
|
return cache.is_empty(elem)
|
||||||
|
|
||||||
|
|
||||||
select_empty.is_pseudo = True
|
|
||||||
|
|
||||||
# }}}
|
# }}}
|
||||||
|
|
||||||
default_dispatch_map = {name.partition('_')[2]:obj for name, obj in globals().items() if name.startswith('select_') and callable(obj)}
|
default_dispatch_map = {name.partition('_')[2]:obj for name, obj in globals().items() if name.startswith('select_') and callable(obj)}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user