1
0
mirror of https://github.com/rkd77/elinks.git synced 2024-07-04 02:35:29 +00:00

Bug 968: Don't use copy_chars in justify_line.

All the needed memory has been allocated before the loop so we can use
copy_screen_chars() directly.  This avoids the assertion failure in
copy_chars() for width==0 and should be a bit faster too.  According
to ISO/IEC 9899:1999 7.21.1p2, memcpy() doesn't copy anything if n==0
(but the pointers must be valid).
This commit is contained in:
Kalle Olavi Niemitalo 2007-07-29 19:57:12 +03:00 committed by Witold Filipczyk
parent eecba4a96c
commit db13653fb0

View File

@ -1132,9 +1132,16 @@ justify_line(struct html_context *html_context, int y)
word_shift = (word * diff) / (spaces - 1);
new_start = word_start + word_shift;
/* Copy the original word, without any spaces. */
copy_chars(html_context, new_start, y, word_len,
&line[word_start]);
/* Assert that the realloc_line() above
* allocated enough memory for the word
* and the preceding spaces. */
assert(LEN(y) >= new_start + word_len);
if_assert_failed continue;
/* Copy the original word, without any spaces.
* word_len may be 0 here. */
copy_screen_chars(&POS(new_start, y),
&line[word_start], word_len);
/* Copy the space that preceded the word,
* duplicating it as many times as necessary.
@ -1146,10 +1153,6 @@ justify_line(struct html_context *html_context, int y)
if (word) {
int spacex;
/* realloc_line() was called above. */
assert(LEN(y) >= new_start);
if_assert_failed continue;
for (spacex = prev_end; spacex < new_start;
++spacex) {
copy_screen_chars(&POS(spacex, y),