mirror of
https://github.com/rkd77/elinks.git
synced 2024-12-04 14:46:47 -05:00
CSS bug 766: Parse the id and class attributes in advance.
time elinks -no-connect -no-home 'http://rss.slashdot.org/Slashdot/slashdot/to?m=5878' Wait until finished loading, then press q and Enter. before 19.96user 0.16system 0:25.97elapsed 77%CPU (0avgtext+0avgdata 0maxresident)k 0inputs+0outputs (0major+3630minor)pagefaults 0swaps after 6.46user 0.12system 0:12.66elapsed 52%CPU (0avgtext+0avgdata 0maxresident)k 0inputs+0outputs (0major+3630minor)pagefaults 0swaps before 18.02user 0.19system 0:23.86elapsed 76%CPU (0avgtext+0avgdata 0maxresident)k 0inputs+0outputs (0major+3572minor)pagefaults 0swaps after 5.73user 0.15system 0:10.02elapsed 58%CPU (0avgtext+0avgdata 0maxresident)k 0inputs+0outputs (0major+3628minor)pagefaults 0swaps before 19.80user 0.15system 0:25.14elapsed 79%CPU (0avgtext+0avgdata 0maxresident)k 0inputs+0outputs (0major+3461minor)pagefaults 0swaps after 6.28user 0.13system 0:11.91elapsed 53%CPU (0avgtext+0avgdata 0maxresident)k 0inputs+0outputs (0major+3626minor)pagefaults 0swaps
This commit is contained in:
parent
5d468daf83
commit
98260f7970
@ -120,7 +120,6 @@ examine_element(struct html_context *html_context, struct css_selector *base,
|
|||||||
struct list_head *selectors, struct html_element *element)
|
struct list_head *selectors, struct html_element *element)
|
||||||
{
|
{
|
||||||
struct css_selector *selector;
|
struct css_selector *selector;
|
||||||
unsigned char *code;
|
|
||||||
|
|
||||||
#ifdef DEBUG_CSS
|
#ifdef DEBUG_CSS
|
||||||
/* Cannot use list_empty() inside the arglist of DBG() because
|
/* Cannot use list_empty() inside the arglist of DBG() because
|
||||||
@ -191,29 +190,27 @@ examine_element(struct html_context *html_context, struct css_selector *base,
|
|||||||
process_found_selector(selector, CST_PSEUDO, base);
|
process_found_selector(selector, CST_PSEUDO, base);
|
||||||
}
|
}
|
||||||
|
|
||||||
code = get_attr_val(element->options, "class", html_context->doc_cp);
|
if (element->attr.class && seltype <= CST_CLASS) {
|
||||||
if (code && seltype <= CST_CLASS) {
|
const unsigned char *class = element->attr.class;
|
||||||
unsigned char *class = code;
|
|
||||||
|
|
||||||
while (class) {
|
for (;;) {
|
||||||
unsigned char *end = strchr(class, ' ');
|
const unsigned char *begin;
|
||||||
|
|
||||||
if (end)
|
while (*class == ' ') ++class;
|
||||||
*end++ = 0;
|
if (*class == '\0') break;
|
||||||
|
begin = class;
|
||||||
|
while (*class != ' ' && *class != '\0') ++class;
|
||||||
|
|
||||||
selector = find_css_selector(selectors, CST_CLASS, rel, class, -1);
|
selector = find_css_selector(selectors, CST_CLASS, rel,
|
||||||
|
begin, class - begin);
|
||||||
process_found_selector(selector, CST_CLASS, base);
|
process_found_selector(selector, CST_CLASS, base);
|
||||||
class = end;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
mem_free_if(code);
|
|
||||||
|
|
||||||
code = get_attr_val(element->options, "id", html_context->doc_cp);
|
if (element->attr.id && seltype <= CST_ID) {
|
||||||
if (code && seltype <= CST_ID) {
|
selector = find_css_selector(selectors, CST_ID, rel, element->attr.id, -1);
|
||||||
selector = find_css_selector(selectors, CST_ID, rel, code, -1);
|
|
||||||
process_found_selector(selector, CST_ID, base);
|
process_found_selector(selector, CST_ID, base);
|
||||||
}
|
}
|
||||||
if (code) mem_free(code);
|
|
||||||
|
|
||||||
#undef process_found_selector
|
#undef process_found_selector
|
||||||
#undef dbginfo
|
#undef dbginfo
|
||||||
|
@ -27,7 +27,7 @@
|
|||||||
struct css_selector *
|
struct css_selector *
|
||||||
find_css_selector(struct list_head *sels, enum css_selector_type type,
|
find_css_selector(struct list_head *sels, enum css_selector_type type,
|
||||||
enum css_selector_relation rel,
|
enum css_selector_relation rel,
|
||||||
unsigned char *name, int namelen)
|
const unsigned char *name, int namelen)
|
||||||
{
|
{
|
||||||
struct css_selector *selector;
|
struct css_selector *selector;
|
||||||
|
|
||||||
|
@ -120,7 +120,7 @@ struct css_selector *get_css_selector(struct list_head *selector_list,
|
|||||||
struct css_selector *find_css_selector(struct list_head *selector_list,
|
struct css_selector *find_css_selector(struct list_head *selector_list,
|
||||||
enum css_selector_type type,
|
enum css_selector_type type,
|
||||||
enum css_selector_relation rel,
|
enum css_selector_relation rel,
|
||||||
unsigned char *name, int namelen);
|
const unsigned char *name, int namelen);
|
||||||
|
|
||||||
#define find_css_base_selector(stylesheet, type, rel, name, namelen) \
|
#define find_css_base_selector(stylesheet, type, rel, name, namelen) \
|
||||||
find_css_selector(&stylesheet->selectors, rel, type, name, namelen)
|
find_css_selector(&stylesheet->selectors, rel, type, name, namelen)
|
||||||
|
@ -52,6 +52,16 @@ struct text_attrib {
|
|||||||
#endif
|
#endif
|
||||||
color_T image_link;
|
color_T image_link;
|
||||||
|
|
||||||
|
#ifdef CONFIG_CSS
|
||||||
|
/* Bug 766: CSS speedup. 56% of CPU time was going to
|
||||||
|
* get_attr_value(). Of those calls, 97% were asking for "id"
|
||||||
|
* or "class". So cache the results. start_element() sets up
|
||||||
|
* these pointers if html_context->options->css_enable;
|
||||||
|
* otherwise they remain NULL. */
|
||||||
|
unsigned char *id;
|
||||||
|
unsigned char *class;
|
||||||
|
#endif
|
||||||
|
|
||||||
unsigned char *select;
|
unsigned char *select;
|
||||||
int select_disabled;
|
int select_disabled;
|
||||||
unsigned int tabindex;
|
unsigned int tabindex;
|
||||||
|
@ -905,6 +905,10 @@ start_element(struct element_info *ei,
|
|||||||
* usually have type != ET_NESTABLE when we either (1)
|
* usually have type != ET_NESTABLE when we either (1)
|
||||||
* rescan on your own from somewhere else (2) html_stack_dup()
|
* rescan on your own from somewhere else (2) html_stack_dup()
|
||||||
* in our own way. --pasky */
|
* in our own way. --pasky */
|
||||||
|
mem_free_set(&html_top->attr.id,
|
||||||
|
get_attr_val(attr, "id", html_context->doc_cp));
|
||||||
|
mem_free_set(&html_top->attr.class,
|
||||||
|
get_attr_val(attr, "class", html_context->doc_cp));
|
||||||
/* Call it now to gain some of the stuff which might affect
|
/* Call it now to gain some of the stuff which might affect
|
||||||
* formatting of some elements. */
|
* formatting of some elements. */
|
||||||
/* FIXME: The caching of the CSS selector is broken, since t can
|
/* FIXME: The caching of the CSS selector is broken, since t can
|
||||||
|
@ -107,6 +107,11 @@ kill_html_stack_item(struct html_context *html_context, struct html_element *e)
|
|||||||
mem_free_if(e->attr.title);
|
mem_free_if(e->attr.title);
|
||||||
mem_free_if(e->attr.select);
|
mem_free_if(e->attr.select);
|
||||||
|
|
||||||
|
#ifdef CONFIG_CSS
|
||||||
|
mem_free_if(e->attr.id);
|
||||||
|
mem_free_if(e->attr.class);
|
||||||
|
#endif
|
||||||
|
|
||||||
mem_free_if(e->attr.onclick);
|
mem_free_if(e->attr.onclick);
|
||||||
mem_free_if(e->attr.ondblclick);
|
mem_free_if(e->attr.ondblclick);
|
||||||
mem_free_if(e->attr.onmouseover);
|
mem_free_if(e->attr.onmouseover);
|
||||||
@ -146,6 +151,8 @@ html_stack_dup(struct html_context *html_context, enum html_element_mortality_ty
|
|||||||
if (ep->attr.title) e->attr.title = stracpy(ep->attr.title);
|
if (ep->attr.title) e->attr.title = stracpy(ep->attr.title);
|
||||||
if (ep->attr.select) e->attr.select = stracpy(ep->attr.select);
|
if (ep->attr.select) e->attr.select = stracpy(ep->attr.select);
|
||||||
|
|
||||||
|
e->attr.id = e->attr.class = NULL;
|
||||||
|
|
||||||
/* We don't want to propagate these. */
|
/* We don't want to propagate these. */
|
||||||
/* XXX: For sure? --pasky */
|
/* XXX: For sure? --pasky */
|
||||||
e->attr.onclick = e->attr.ondblclick = e->attr.onmouseover = e->attr.onhover
|
e->attr.onclick = e->attr.ondblclick = e->attr.onmouseover = e->attr.onhover
|
||||||
|
Loading…
Reference in New Issue
Block a user