mirror of
https://github.com/vim/vim.git
synced 2025-09-26 04:04:07 -04:00
patch 7.4.783
Problem: copy_chars() and copy_spaces() are inefficient. Solution: Use memset() instead. (Dominique Pelle)
This commit is contained in:
@@ -250,7 +250,7 @@ getcmdline(firstc, count, indent)
|
|||||||
/* autoindent for :insert and :append */
|
/* autoindent for :insert and :append */
|
||||||
if (firstc <= 0)
|
if (firstc <= 0)
|
||||||
{
|
{
|
||||||
copy_spaces(ccline.cmdbuff, indent);
|
vim_memset(ccline.cmdbuff, ' ', indent);
|
||||||
ccline.cmdbuff[indent] = NUL;
|
ccline.cmdbuff[indent] = NUL;
|
||||||
ccline.cmdpos = indent;
|
ccline.cmdpos = indent;
|
||||||
ccline.cmdspos = indent;
|
ccline.cmdspos = indent;
|
||||||
|
34
src/misc2.c
34
src/misc2.c
@@ -1599,40 +1599,6 @@ strup_save(orig)
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/*
|
|
||||||
* copy a space a number of times
|
|
||||||
*/
|
|
||||||
void
|
|
||||||
copy_spaces(ptr, count)
|
|
||||||
char_u *ptr;
|
|
||||||
size_t count;
|
|
||||||
{
|
|
||||||
size_t i = count;
|
|
||||||
char_u *p = ptr;
|
|
||||||
|
|
||||||
while (i--)
|
|
||||||
*p++ = ' ';
|
|
||||||
}
|
|
||||||
|
|
||||||
#if defined(FEAT_VISUALEXTRA) || defined(PROTO)
|
|
||||||
/*
|
|
||||||
* Copy a character a number of times.
|
|
||||||
* Does not work for multi-byte characters!
|
|
||||||
*/
|
|
||||||
void
|
|
||||||
copy_chars(ptr, count, c)
|
|
||||||
char_u *ptr;
|
|
||||||
size_t count;
|
|
||||||
int c;
|
|
||||||
{
|
|
||||||
size_t i = count;
|
|
||||||
char_u *p = ptr;
|
|
||||||
|
|
||||||
while (i--)
|
|
||||||
*p++ = c;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* delete spaces at the end of a string
|
* delete spaces at the end of a string
|
||||||
*/
|
*/
|
||||||
|
32
src/ops.c
32
src/ops.c
@@ -442,8 +442,8 @@ shift_block(oap, amount)
|
|||||||
return;
|
return;
|
||||||
vim_memset(newp, NUL, (size_t)(bd.textcol + i + j + len));
|
vim_memset(newp, NUL, (size_t)(bd.textcol + i + j + len));
|
||||||
mch_memmove(newp, oldp, (size_t)bd.textcol);
|
mch_memmove(newp, oldp, (size_t)bd.textcol);
|
||||||
copy_chars(newp + bd.textcol, (size_t)i, TAB);
|
vim_memset(newp + bd.textcol, TAB, (size_t)i);
|
||||||
copy_spaces(newp + bd.textcol + i, (size_t)j);
|
vim_memset(newp + bd.textcol + i, ' ', (size_t)j);
|
||||||
/* the end */
|
/* the end */
|
||||||
mch_memmove(newp + bd.textcol + i + j, bd.textstart, (size_t)len);
|
mch_memmove(newp + bd.textcol + i + j, bd.textstart, (size_t)len);
|
||||||
}
|
}
|
||||||
@@ -535,7 +535,7 @@ shift_block(oap, amount)
|
|||||||
if (newp == NULL)
|
if (newp == NULL)
|
||||||
return;
|
return;
|
||||||
mch_memmove(newp, oldp, (size_t)(verbatim_copy_end - oldp));
|
mch_memmove(newp, oldp, (size_t)(verbatim_copy_end - oldp));
|
||||||
copy_spaces(newp + (verbatim_copy_end - oldp), (size_t)fill);
|
vim_memset(newp + (verbatim_copy_end - oldp), ' ', (size_t)fill);
|
||||||
STRMOVE(newp + (verbatim_copy_end - oldp) + fill, non_white);
|
STRMOVE(newp + (verbatim_copy_end - oldp) + fill, non_white);
|
||||||
}
|
}
|
||||||
/* replace the line */
|
/* replace the line */
|
||||||
@@ -638,7 +638,7 @@ block_insert(oap, s, b_insert, bdp)
|
|||||||
oldp += offset;
|
oldp += offset;
|
||||||
|
|
||||||
/* insert pre-padding */
|
/* insert pre-padding */
|
||||||
copy_spaces(newp + offset, (size_t)spaces);
|
vim_memset(newp + offset, ' ', (size_t)spaces);
|
||||||
|
|
||||||
/* copy the new text */
|
/* copy the new text */
|
||||||
mch_memmove(newp + offset + spaces, s, (size_t)s_len);
|
mch_memmove(newp + offset + spaces, s, (size_t)s_len);
|
||||||
@@ -647,7 +647,7 @@ block_insert(oap, s, b_insert, bdp)
|
|||||||
if (spaces && !bdp->is_short)
|
if (spaces && !bdp->is_short)
|
||||||
{
|
{
|
||||||
/* insert post-padding */
|
/* insert post-padding */
|
||||||
copy_spaces(newp + offset + spaces, (size_t)(p_ts - spaces));
|
vim_memset(newp + offset + spaces, ' ', (size_t)(p_ts - spaces));
|
||||||
/* We're splitting a TAB, don't copy it. */
|
/* We're splitting a TAB, don't copy it. */
|
||||||
oldp++;
|
oldp++;
|
||||||
/* We allowed for that TAB, remember this now */
|
/* We allowed for that TAB, remember this now */
|
||||||
@@ -1831,7 +1831,7 @@ op_delete(oap)
|
|||||||
/* copy up to deleted part */
|
/* copy up to deleted part */
|
||||||
mch_memmove(newp, oldp, (size_t)bd.textcol);
|
mch_memmove(newp, oldp, (size_t)bd.textcol);
|
||||||
/* insert spaces */
|
/* insert spaces */
|
||||||
copy_spaces(newp + bd.textcol,
|
vim_memset(newp + bd.textcol, ' ',
|
||||||
(size_t)(bd.startspaces + bd.endspaces));
|
(size_t)(bd.startspaces + bd.endspaces));
|
||||||
/* copy the part after the deleted part */
|
/* copy the part after the deleted part */
|
||||||
oldp += bd.textcol + bd.textlen;
|
oldp += bd.textcol + bd.textlen;
|
||||||
@@ -2132,7 +2132,7 @@ op_replace(oap, c)
|
|||||||
mch_memmove(newp, oldp, (size_t)bd.textcol);
|
mch_memmove(newp, oldp, (size_t)bd.textcol);
|
||||||
oldp += bd.textcol + bd.textlen;
|
oldp += bd.textcol + bd.textlen;
|
||||||
/* insert pre-spaces */
|
/* insert pre-spaces */
|
||||||
copy_spaces(newp + bd.textcol, (size_t)bd.startspaces);
|
vim_memset(newp + bd.textcol, ' ', (size_t)bd.startspaces);
|
||||||
/* insert replacement chars CHECK FOR ALLOCATED SPACE */
|
/* insert replacement chars CHECK FOR ALLOCATED SPACE */
|
||||||
/* -1/-2 is used for entering CR literally. */
|
/* -1/-2 is used for entering CR literally. */
|
||||||
if (had_ctrl_v_cr || (c != '\r' && c != '\n'))
|
if (had_ctrl_v_cr || (c != '\r' && c != '\n'))
|
||||||
@@ -2146,11 +2146,11 @@ op_replace(oap, c)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
#endif
|
#endif
|
||||||
copy_chars(newp + STRLEN(newp), (size_t)numc, c);
|
vim_memset(newp + STRLEN(newp), c, (size_t)numc);
|
||||||
if (!bd.is_short)
|
if (!bd.is_short)
|
||||||
{
|
{
|
||||||
/* insert post-spaces */
|
/* insert post-spaces */
|
||||||
copy_spaces(newp + STRLEN(newp), (size_t)bd.endspaces);
|
vim_memset(newp + STRLEN(newp), ' ', (size_t)bd.endspaces);
|
||||||
/* copy the part after the changed part */
|
/* copy the part after the changed part */
|
||||||
STRMOVE(newp + STRLEN(newp), oldp);
|
STRMOVE(newp + STRLEN(newp), oldp);
|
||||||
}
|
}
|
||||||
@@ -2831,7 +2831,7 @@ op_change(oap)
|
|||||||
mch_memmove(newp, oldp, (size_t)bd.textcol);
|
mch_memmove(newp, oldp, (size_t)bd.textcol);
|
||||||
offset = bd.textcol;
|
offset = bd.textcol;
|
||||||
# ifdef FEAT_VIRTUALEDIT
|
# ifdef FEAT_VIRTUALEDIT
|
||||||
copy_spaces(newp + offset, (size_t)vpos.coladd);
|
vim_memset(newp + offset, ' ', (size_t)vpos.coladd);
|
||||||
offset += vpos.coladd;
|
offset += vpos.coladd;
|
||||||
# endif
|
# endif
|
||||||
mch_memmove(newp + offset, ins_text, (size_t)ins_len);
|
mch_memmove(newp + offset, ins_text, (size_t)ins_len);
|
||||||
@@ -3272,11 +3272,11 @@ yank_copy_line(bd, y_idx)
|
|||||||
== NULL)
|
== NULL)
|
||||||
return FAIL;
|
return FAIL;
|
||||||
y_current->y_array[y_idx] = pnew;
|
y_current->y_array[y_idx] = pnew;
|
||||||
copy_spaces(pnew, (size_t)bd->startspaces);
|
vim_memset(pnew, ' ', (size_t)bd->startspaces);
|
||||||
pnew += bd->startspaces;
|
pnew += bd->startspaces;
|
||||||
mch_memmove(pnew, bd->textstart, (size_t)bd->textlen);
|
mch_memmove(pnew, bd->textstart, (size_t)bd->textlen);
|
||||||
pnew += bd->textlen;
|
pnew += bd->textlen;
|
||||||
copy_spaces(pnew, (size_t)bd->endspaces);
|
vim_memset(pnew, ' ', (size_t)bd->endspaces);
|
||||||
pnew += bd->endspaces;
|
pnew += bd->endspaces;
|
||||||
*pnew = NUL;
|
*pnew = NUL;
|
||||||
return OK;
|
return OK;
|
||||||
@@ -3690,7 +3690,7 @@ do_put(regname, dir, count, flags)
|
|||||||
mch_memmove(ptr, oldp, (size_t)bd.textcol);
|
mch_memmove(ptr, oldp, (size_t)bd.textcol);
|
||||||
ptr += bd.textcol;
|
ptr += bd.textcol;
|
||||||
/* may insert some spaces before the new text */
|
/* may insert some spaces before the new text */
|
||||||
copy_spaces(ptr, (size_t)bd.startspaces);
|
vim_memset(ptr, ' ', (size_t)bd.startspaces);
|
||||||
ptr += bd.startspaces;
|
ptr += bd.startspaces;
|
||||||
/* insert the new text */
|
/* insert the new text */
|
||||||
for (j = 0; j < count; ++j)
|
for (j = 0; j < count; ++j)
|
||||||
@@ -3701,12 +3701,12 @@ do_put(regname, dir, count, flags)
|
|||||||
/* insert block's trailing spaces only if there's text behind */
|
/* insert block's trailing spaces only if there's text behind */
|
||||||
if ((j < count - 1 || !shortline) && spaces)
|
if ((j < count - 1 || !shortline) && spaces)
|
||||||
{
|
{
|
||||||
copy_spaces(ptr, (size_t)spaces);
|
vim_memset(ptr, ' ', (size_t)spaces);
|
||||||
ptr += spaces;
|
ptr += spaces;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/* may insert some spaces after the new text */
|
/* may insert some spaces after the new text */
|
||||||
copy_spaces(ptr, (size_t)bd.endspaces);
|
vim_memset(ptr, ' ', (size_t)bd.endspaces);
|
||||||
ptr += bd.endspaces;
|
ptr += bd.endspaces;
|
||||||
/* move the text after the cursor to the end of the line. */
|
/* move the text after the cursor to the end of the line. */
|
||||||
mch_memmove(ptr, oldp + bd.textcol + delcount,
|
mch_memmove(ptr, oldp + bd.textcol + delcount,
|
||||||
@@ -4522,7 +4522,7 @@ do_join(count, insert_space, save_undo, use_formatoptions, setmark)
|
|||||||
if (spaces[t] > 0)
|
if (spaces[t] > 0)
|
||||||
{
|
{
|
||||||
cend -= spaces[t];
|
cend -= spaces[t];
|
||||||
copy_spaces(cend, (size_t)(spaces[t]));
|
vim_memset(cend, ' ', (size_t)(spaces[t]));
|
||||||
}
|
}
|
||||||
mark_col_adjust(curwin->w_cursor.lnum + t, (colnr_T)0, (linenr_T)-t,
|
mark_col_adjust(curwin->w_cursor.lnum + t, (colnr_T)0, (linenr_T)-t,
|
||||||
(long)(cend - newp + spaces[t] - (curr - curr_start)));
|
(long)(cend - newp + spaces[t] - (curr - curr_start)));
|
||||||
|
@@ -37,8 +37,6 @@ char_u *vim_strsave_up __ARGS((char_u *string));
|
|||||||
char_u *vim_strnsave_up __ARGS((char_u *string, int len));
|
char_u *vim_strnsave_up __ARGS((char_u *string, int len));
|
||||||
void vim_strup __ARGS((char_u *p));
|
void vim_strup __ARGS((char_u *p));
|
||||||
char_u *strup_save __ARGS((char_u *orig));
|
char_u *strup_save __ARGS((char_u *orig));
|
||||||
void copy_spaces __ARGS((char_u *ptr, size_t count));
|
|
||||||
void copy_chars __ARGS((char_u *ptr, size_t count, int c));
|
|
||||||
void del_trailing_spaces __ARGS((char_u *ptr));
|
void del_trailing_spaces __ARGS((char_u *ptr));
|
||||||
void vim_strncpy __ARGS((char_u *to, char_u *from, size_t len));
|
void vim_strncpy __ARGS((char_u *to, char_u *from, size_t len));
|
||||||
void vim_strcat __ARGS((char_u *to, char_u *from, size_t tosize));
|
void vim_strcat __ARGS((char_u *to, char_u *from, size_t tosize));
|
||||||
|
@@ -2833,7 +2833,7 @@ fill_foldcolumn(p, wp, closed, lnum)
|
|||||||
int fdc = compute_foldcolumn(wp, 0);
|
int fdc = compute_foldcolumn(wp, 0);
|
||||||
|
|
||||||
/* Init to all spaces. */
|
/* Init to all spaces. */
|
||||||
copy_spaces(p, (size_t)fdc);
|
vim_memset(p, ' ', (size_t)fdc);
|
||||||
|
|
||||||
level = win_foldinfo.fi_level;
|
level = win_foldinfo.fi_level;
|
||||||
if (level > 0)
|
if (level > 0)
|
||||||
|
@@ -741,6 +741,8 @@ static char *(features[]) =
|
|||||||
|
|
||||||
static int included_patches[] =
|
static int included_patches[] =
|
||||||
{ /* Add new patch number below this line */
|
{ /* Add new patch number below this line */
|
||||||
|
/**/
|
||||||
|
783,
|
||||||
/**/
|
/**/
|
||||||
782,
|
782,
|
||||||
/**/
|
/**/
|
||||||
|
Reference in New Issue
Block a user