[patch] don't allocate tagnames on stack
Hi, here is another patch that avoids some malloc/free calls. Cheers, Johannes diff --git a/src/html.cc b/src/html.cc --- a/src/html.cc +++ b/src/html.cc @@ -194,7 +194,7 @@ struct _DilloLinkImage { }; struct _DilloHtmlState { - char *tag_name; + const char *tag_name; dw::core::style::Style *style, *table_cell_style; DilloHtmlParseMode parse_mode; DilloHtmlTableMode table_mode; @@ -815,7 +815,7 @@ DilloHtml::DilloHtml(BrowserWindow *p_bw stack = new misc::SimpleVector <DilloHtmlState> (16); stack->increase(); - stack->getRef(0)->tag_name = dStrdup("none"); + stack->getRef(0)->tag_name = "none"; stack->getRef(0)->style = NULL; stack->getRef(0)->table_cell_style = NULL; stack->getRef(0)->parse_mode = DILLO_HTML_PARSE_MODE_INIT; @@ -1014,7 +1014,6 @@ void DilloHtml::closeParser(int ClientKe Html_tag_cleanup_at_close(this, stack->getRef(si)->tag_idx); } } - dFree(stack->getRef(0)->tag_name); /* "none" */ (stack->getRef(0)->style)->unref (); /* template style */ delete (stack); @@ -1596,18 +1595,14 @@ static void Html_eventually_pop_dw(Dillo */ static void Html_push_tag(DilloHtml *html, int tag_idx) { - char *tagstr; int n_items; - - /* Save the element's name (no parameters) into tagstr. */ - tagstr = dStrdup(Tags[tag_idx].name); n_items = html->stack->size (); html->stack->increase (); /* We'll copy the former stack item and just change the tag and its index * instead of copying all fields except for tag. --Jcid */ *html->stack->getRef(n_items) = *html->stack->getRef(n_items - 1); - html->stack->getRef(n_items)->tag_name = tagstr; + html->stack->getRef(n_items)->tag_name = Tags[tag_idx].name; html->stack->getRef(n_items)->tag_idx = tag_idx; /* proper memory management, may be unref'd later */ (S_TOP(html)->style)->ref (); @@ -1635,7 +1630,6 @@ static void Html_real_pop_tag(DilloHtml (S_TOP(html)->style)->unref (); if (S_TOP(html)->table_cell_style) (S_TOP(html)->table_cell_style)->unref (); - dFree(S_TOP(html)->tag_name); hand_over_break = S_TOP(html)->hand_over_break; html->stack->setSize (html->stack->size() - 1); Html_eventually_pop_dw(html, hand_over_break); @@ -5582,7 +5576,7 @@ static int Html_write_raw(DilloHtml *htm DILLO_HTML_PARSE_MODE_VERBATIM) { /* Non HTML code here, let's skip until closing tag */ do { - char *tag = S_TOP(html)->tag_name; + const char *tag = S_TOP(html)->tag_name; buf_index += strcspn(buf + buf_index, "<"); if (buf_index + (int)strlen(tag) + 3 > bufsize) { buf_index = bufsize;
On Thu, Mar 13, 2008 at 09:01:37PM +0100, Johannes Hofmann wrote:
Hi,
here is another patch that avoids some malloc/free calls.
I decided to completely remove tag_name, and to use Tags[tag_idx]. Please check the patch in CVS. BTW, with regard to these optimizations (which I was very fond of), profiling showed me that the zen of speed is to attack the main bottleneck... -- Cheers Jorge.-
On Sun, Mar 16, 2008 at 10:47:07AM -0400, Jorge Arellano Cid wrote:
On Thu, Mar 13, 2008 at 09:01:37PM +0100, Johannes Hofmann wrote:
Hi,
here is another patch that avoids some malloc/free calls.
I decided to completely remove tag_name, and to use Tags[tag_idx]. Please check the patch in CVS.
Cool. That's even better.
BTW, with regard to these optimizations (which I was very fond of), profiling showed me that the zen of speed is to attack the main bottleneck...
Can you build a statically linked binary with profiling enabled? Here it does not work for some reason, so the timings in the gprof output are bogus. Only the counters work reliably. Cheers, Johannes
On Sun, Mar 16, 2008 at 05:05:57PM +0100, Johannes Hofmann wrote:
On Sun, Mar 16, 2008 at 10:47:07AM -0400, Jorge Arellano Cid wrote:
On Thu, Mar 13, 2008 at 09:01:37PM +0100, Johannes Hofmann wrote:
Hi,
here is another patch that avoids some malloc/free calls.
I decided to completely remove tag_name, and to use Tags[tag_idx]. Please check the patch in CVS.
Cool. That's even better.
BTW, with regard to these optimizations (which I was very fond of), profiling showed me that the zen of speed is to attack the main bottleneck...
Can you build a statically linked binary with profiling enabled? Here it does not work for some reason, so the timings in the gprof output are bogus. Only the counters work reliably.
I've done it lots of times in the past, with: ./configure --enable-gprof or CFLAGS="-g -O0" CXXFLAGS="-g -O0" ./configure --enable-gprof but now that I test, it doesn't work anymore! !? -- Cheers Jorge.-
participants (2)
-
jcid@dillo.org
-
Johannes.Hofmann@gmx.de