diff options
author | jcid <devnull@localhost> | 2008-05-21 22:45:23 +0200 |
---|---|---|
committer | jcid <devnull@localhost> | 2008-05-21 22:45:23 +0200 |
commit | 2164601461cf170ed66ffd9aef2cec0834662cdc (patch) | |
tree | 62ec5471b1168138097690c6e104e51383c3e55a /src | |
parent | 3fb8bcfd79cb01ca3feaa1ff92876dba6e711381 (diff) |
- Small memory optimization in whitespace handling in PRE elements.
Diffstat (limited to 'src')
-rw-r--r-- | src/html.cc | 19 |
1 files changed, 15 insertions, 4 deletions
diff --git a/src/html.cc b/src/html.cc index 946ecd54..1c811092 100644 --- a/src/html.cc +++ b/src/html.cc @@ -1445,11 +1445,19 @@ static void Html_process_space(DilloHtml *html, const char *space, html->SPCPending = FALSE; } else if (parse_mode == DILLO_HTML_PARSE_MODE_PRE) { + int spaceCnt = 0; + /* re-scan the string for characters that cause line breaks */ for (i = 0; i < spacesize; i++) { /* Support for "\r", "\n" and "\r\n" line breaks (skips the first) */ if (!html->PreFirstChar && (space[i] == '\r' || (space[i] == '\n' && !html->PrevWasCR))) { + + if (spaceCnt) { + DW2TB(html->dw)->addText (dStrnfill(spaceCnt, ' '), + S_TOP(html)->style); + spaceCnt = 0; + } DW2TB(html->dw)->addLinebreak (S_TOP(html)->style); html->pre_column = 0; } @@ -1464,19 +1472,22 @@ static void Html_process_space(DilloHtml *html, const char *space, if (prefs.show_extra_warnings) MSG_HTML("TAB character inside <PRE>\n"); offset = TAB_SIZE - html->pre_column % TAB_SIZE; - DW2TB(html->dw)->addText (dStrnfill(offset, ' '), - S_TOP(html)->style); + spaceCnt += offset; html->pre_column += offset; break; default: - DW2TB(html->dw)->addText (dStrndup(space + i, 1), - S_TOP(html)->style); + spaceCnt++; html->pre_column++; break; } html->PrevWasCR = (space[i] == '\r'); } + + if (spaceCnt) { + DW2TB(html->dw)->addText (dStrnfill(spaceCnt, ' '), + S_TOP(html)->style); + } html->SPCPending = FALSE; } else { |