1
0
mirror of https://github.com/rkd77/elinks.git synced 2024-06-24 00:56:14 +00: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:
Kalle Olavi Niemitalo 2007-07-15 22:19:30 +03:00 committed by Kalle Olavi Niemitalo
parent 5d468daf83
commit 98260f7970
6 changed files with 35 additions and 17 deletions

View File

@ -120,7 +120,6 @@ examine_element(struct html_context *html_context, struct css_selector *base,
struct list_head *selectors, struct html_element *element)
{
struct css_selector *selector;
unsigned char *code;
#ifdef DEBUG_CSS
/* 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);
}
code = get_attr_val(element->options, "class", html_context->doc_cp);
if (code && seltype <= CST_CLASS) {
unsigned char *class = code;
if (element->attr.class && seltype <= CST_CLASS) {
const unsigned char *class = element->attr.class;
while (class) {
unsigned char *end = strchr(class, ' ');
for (;;) {
const unsigned char *begin;
if (end)
*end++ = 0;
while (*class == ' ') ++class;
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);
class = end;
}
}
mem_free_if(code);
code = get_attr_val(element->options, "id", html_context->doc_cp);
if (code && seltype <= CST_ID) {
selector = find_css_selector(selectors, CST_ID, rel, code, -1);
if (element->attr.id && seltype <= CST_ID) {
selector = find_css_selector(selectors, CST_ID, rel, element->attr.id, -1);
process_found_selector(selector, CST_ID, base);
}
if (code) mem_free(code);
#undef process_found_selector
#undef dbginfo

View File

@ -27,7 +27,7 @@
struct css_selector *
find_css_selector(struct list_head *sels, enum css_selector_type type,
enum css_selector_relation rel,
unsigned char *name, int namelen)
const unsigned char *name, int namelen)
{
struct css_selector *selector;

View File

@ -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,
enum css_selector_type type,
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) \
find_css_selector(&stylesheet->selectors, rel, type, name, namelen)

View File

@ -52,6 +52,16 @@ struct text_attrib {
#endif
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;
int select_disabled;
unsigned int tabindex;

View File

@ -905,6 +905,10 @@ start_element(struct element_info *ei,
* usually have type != ET_NESTABLE when we either (1)
* rescan on your own from somewhere else (2) html_stack_dup()
* 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
* formatting of some elements. */
/* FIXME: The caching of the CSS selector is broken, since t can

View File

@ -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.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.ondblclick);
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.select) e->attr.select = stracpy(ep->attr.select);
e->attr.id = e->attr.class = NULL;
/* We don't want to propagate these. */
/* XXX: For sure? --pasky */
e->attr.onclick = e->attr.ondblclick = e->attr.onmouseover = e->attr.onhover