Mercurial > vim
comparison src/ops.c @ 6929:e55929fca0cf v7.4.783
patch 7.4.783
Problem: copy_chars() and copy_spaces() are inefficient.
Solution: Use memset() instead. (Dominique Pelle)
author | Bram Moolenaar <bram@vim.org> |
---|---|
date | Fri, 17 Jul 2015 13:22:51 +0200 |
parents | 58d9f967ae1a |
children | 62ba356c2d4e |
comparison
equal
deleted
inserted
replaced
6928:e607a8d58e64 | 6929:e55929fca0cf |
---|---|
440 newp = alloc_check((unsigned)(bd.textcol + i + j + len)); | 440 newp = alloc_check((unsigned)(bd.textcol + i + j + len)); |
441 if (newp == NULL) | 441 if (newp == NULL) |
442 return; | 442 return; |
443 vim_memset(newp, NUL, (size_t)(bd.textcol + i + j + len)); | 443 vim_memset(newp, NUL, (size_t)(bd.textcol + i + j + len)); |
444 mch_memmove(newp, oldp, (size_t)bd.textcol); | 444 mch_memmove(newp, oldp, (size_t)bd.textcol); |
445 copy_chars(newp + bd.textcol, (size_t)i, TAB); | 445 vim_memset(newp + bd.textcol, TAB, (size_t)i); |
446 copy_spaces(newp + bd.textcol + i, (size_t)j); | 446 vim_memset(newp + bd.textcol + i, ' ', (size_t)j); |
447 /* the end */ | 447 /* the end */ |
448 mch_memmove(newp + bd.textcol + i + j, bd.textstart, (size_t)len); | 448 mch_memmove(newp + bd.textcol + i + j, bd.textstart, (size_t)len); |
449 } | 449 } |
450 else /* left */ | 450 else /* left */ |
451 { | 451 { |
533 | 533 |
534 newp = alloc_check(new_line_len); | 534 newp = alloc_check(new_line_len); |
535 if (newp == NULL) | 535 if (newp == NULL) |
536 return; | 536 return; |
537 mch_memmove(newp, oldp, (size_t)(verbatim_copy_end - oldp)); | 537 mch_memmove(newp, oldp, (size_t)(verbatim_copy_end - oldp)); |
538 copy_spaces(newp + (verbatim_copy_end - oldp), (size_t)fill); | 538 vim_memset(newp + (verbatim_copy_end - oldp), ' ', (size_t)fill); |
539 STRMOVE(newp + (verbatim_copy_end - oldp) + fill, non_white); | 539 STRMOVE(newp + (verbatim_copy_end - oldp) + fill, non_white); |
540 } | 540 } |
541 /* replace the line */ | 541 /* replace the line */ |
542 ml_replace(curwin->w_cursor.lnum, newp, FALSE); | 542 ml_replace(curwin->w_cursor.lnum, newp, FALSE); |
543 changed_bytes(curwin->w_cursor.lnum, (colnr_T)bd.textcol); | 543 changed_bytes(curwin->w_cursor.lnum, (colnr_T)bd.textcol); |
636 /* copy up to shifted part */ | 636 /* copy up to shifted part */ |
637 mch_memmove(newp, oldp, (size_t)(offset)); | 637 mch_memmove(newp, oldp, (size_t)(offset)); |
638 oldp += offset; | 638 oldp += offset; |
639 | 639 |
640 /* insert pre-padding */ | 640 /* insert pre-padding */ |
641 copy_spaces(newp + offset, (size_t)spaces); | 641 vim_memset(newp + offset, ' ', (size_t)spaces); |
642 | 642 |
643 /* copy the new text */ | 643 /* copy the new text */ |
644 mch_memmove(newp + offset + spaces, s, (size_t)s_len); | 644 mch_memmove(newp + offset + spaces, s, (size_t)s_len); |
645 offset += s_len; | 645 offset += s_len; |
646 | 646 |
647 if (spaces && !bdp->is_short) | 647 if (spaces && !bdp->is_short) |
648 { | 648 { |
649 /* insert post-padding */ | 649 /* insert post-padding */ |
650 copy_spaces(newp + offset + spaces, (size_t)(p_ts - spaces)); | 650 vim_memset(newp + offset + spaces, ' ', (size_t)(p_ts - spaces)); |
651 /* We're splitting a TAB, don't copy it. */ | 651 /* We're splitting a TAB, don't copy it. */ |
652 oldp++; | 652 oldp++; |
653 /* We allowed for that TAB, remember this now */ | 653 /* We allowed for that TAB, remember this now */ |
654 count++; | 654 count++; |
655 } | 655 } |
1829 if (newp == NULL) | 1829 if (newp == NULL) |
1830 continue; | 1830 continue; |
1831 /* copy up to deleted part */ | 1831 /* copy up to deleted part */ |
1832 mch_memmove(newp, oldp, (size_t)bd.textcol); | 1832 mch_memmove(newp, oldp, (size_t)bd.textcol); |
1833 /* insert spaces */ | 1833 /* insert spaces */ |
1834 copy_spaces(newp + bd.textcol, | 1834 vim_memset(newp + bd.textcol, ' ', |
1835 (size_t)(bd.startspaces + bd.endspaces)); | 1835 (size_t)(bd.startspaces + bd.endspaces)); |
1836 /* copy the part after the deleted part */ | 1836 /* copy the part after the deleted part */ |
1837 oldp += bd.textcol + bd.textlen; | 1837 oldp += bd.textcol + bd.textlen; |
1838 STRMOVE(newp + bd.textcol + bd.startspaces + bd.endspaces, oldp); | 1838 STRMOVE(newp + bd.textcol + bd.startspaces + bd.endspaces, oldp); |
1839 /* replace the line */ | 1839 /* replace the line */ |
2130 vim_memset(newp, NUL, (size_t)(oldlen + 1 + n)); | 2130 vim_memset(newp, NUL, (size_t)(oldlen + 1 + n)); |
2131 /* copy up to deleted part */ | 2131 /* copy up to deleted part */ |
2132 mch_memmove(newp, oldp, (size_t)bd.textcol); | 2132 mch_memmove(newp, oldp, (size_t)bd.textcol); |
2133 oldp += bd.textcol + bd.textlen; | 2133 oldp += bd.textcol + bd.textlen; |
2134 /* insert pre-spaces */ | 2134 /* insert pre-spaces */ |
2135 copy_spaces(newp + bd.textcol, (size_t)bd.startspaces); | 2135 vim_memset(newp + bd.textcol, ' ', (size_t)bd.startspaces); |
2136 /* insert replacement chars CHECK FOR ALLOCATED SPACE */ | 2136 /* insert replacement chars CHECK FOR ALLOCATED SPACE */ |
2137 /* -1/-2 is used for entering CR literally. */ | 2137 /* -1/-2 is used for entering CR literally. */ |
2138 if (had_ctrl_v_cr || (c != '\r' && c != '\n')) | 2138 if (had_ctrl_v_cr || (c != '\r' && c != '\n')) |
2139 { | 2139 { |
2140 #ifdef FEAT_MBYTE | 2140 #ifdef FEAT_MBYTE |
2144 while (--num_chars >= 0) | 2144 while (--num_chars >= 0) |
2145 n += (*mb_char2bytes)(c, newp + n); | 2145 n += (*mb_char2bytes)(c, newp + n); |
2146 } | 2146 } |
2147 else | 2147 else |
2148 #endif | 2148 #endif |
2149 copy_chars(newp + STRLEN(newp), (size_t)numc, c); | 2149 vim_memset(newp + STRLEN(newp), c, (size_t)numc); |
2150 if (!bd.is_short) | 2150 if (!bd.is_short) |
2151 { | 2151 { |
2152 /* insert post-spaces */ | 2152 /* insert post-spaces */ |
2153 copy_spaces(newp + STRLEN(newp), (size_t)bd.endspaces); | 2153 vim_memset(newp + STRLEN(newp), ' ', (size_t)bd.endspaces); |
2154 /* copy the part after the changed part */ | 2154 /* copy the part after the changed part */ |
2155 STRMOVE(newp + STRLEN(newp), oldp); | 2155 STRMOVE(newp + STRLEN(newp), oldp); |
2156 } | 2156 } |
2157 } | 2157 } |
2158 else | 2158 else |
2829 continue; | 2829 continue; |
2830 /* copy up to block start */ | 2830 /* copy up to block start */ |
2831 mch_memmove(newp, oldp, (size_t)bd.textcol); | 2831 mch_memmove(newp, oldp, (size_t)bd.textcol); |
2832 offset = bd.textcol; | 2832 offset = bd.textcol; |
2833 # ifdef FEAT_VIRTUALEDIT | 2833 # ifdef FEAT_VIRTUALEDIT |
2834 copy_spaces(newp + offset, (size_t)vpos.coladd); | 2834 vim_memset(newp + offset, ' ', (size_t)vpos.coladd); |
2835 offset += vpos.coladd; | 2835 offset += vpos.coladd; |
2836 # endif | 2836 # endif |
2837 mch_memmove(newp + offset, ins_text, (size_t)ins_len); | 2837 mch_memmove(newp + offset, ins_text, (size_t)ins_len); |
2838 offset += ins_len; | 2838 offset += ins_len; |
2839 oldp += bd.textcol; | 2839 oldp += bd.textcol; |
3270 | 3270 |
3271 if ((pnew = alloc(bd->startspaces + bd->endspaces + bd->textlen + 1)) | 3271 if ((pnew = alloc(bd->startspaces + bd->endspaces + bd->textlen + 1)) |
3272 == NULL) | 3272 == NULL) |
3273 return FAIL; | 3273 return FAIL; |
3274 y_current->y_array[y_idx] = pnew; | 3274 y_current->y_array[y_idx] = pnew; |
3275 copy_spaces(pnew, (size_t)bd->startspaces); | 3275 vim_memset(pnew, ' ', (size_t)bd->startspaces); |
3276 pnew += bd->startspaces; | 3276 pnew += bd->startspaces; |
3277 mch_memmove(pnew, bd->textstart, (size_t)bd->textlen); | 3277 mch_memmove(pnew, bd->textstart, (size_t)bd->textlen); |
3278 pnew += bd->textlen; | 3278 pnew += bd->textlen; |
3279 copy_spaces(pnew, (size_t)bd->endspaces); | 3279 vim_memset(pnew, ' ', (size_t)bd->endspaces); |
3280 pnew += bd->endspaces; | 3280 pnew += bd->endspaces; |
3281 *pnew = NUL; | 3281 *pnew = NUL; |
3282 return OK; | 3282 return OK; |
3283 } | 3283 } |
3284 | 3284 |
3688 /* copy part up to cursor to new line */ | 3688 /* copy part up to cursor to new line */ |
3689 ptr = newp; | 3689 ptr = newp; |
3690 mch_memmove(ptr, oldp, (size_t)bd.textcol); | 3690 mch_memmove(ptr, oldp, (size_t)bd.textcol); |
3691 ptr += bd.textcol; | 3691 ptr += bd.textcol; |
3692 /* may insert some spaces before the new text */ | 3692 /* may insert some spaces before the new text */ |
3693 copy_spaces(ptr, (size_t)bd.startspaces); | 3693 vim_memset(ptr, ' ', (size_t)bd.startspaces); |
3694 ptr += bd.startspaces; | 3694 ptr += bd.startspaces; |
3695 /* insert the new text */ | 3695 /* insert the new text */ |
3696 for (j = 0; j < count; ++j) | 3696 for (j = 0; j < count; ++j) |
3697 { | 3697 { |
3698 mch_memmove(ptr, y_array[i], (size_t)yanklen); | 3698 mch_memmove(ptr, y_array[i], (size_t)yanklen); |
3699 ptr += yanklen; | 3699 ptr += yanklen; |
3700 | 3700 |
3701 /* insert block's trailing spaces only if there's text behind */ | 3701 /* insert block's trailing spaces only if there's text behind */ |
3702 if ((j < count - 1 || !shortline) && spaces) | 3702 if ((j < count - 1 || !shortline) && spaces) |
3703 { | 3703 { |
3704 copy_spaces(ptr, (size_t)spaces); | 3704 vim_memset(ptr, ' ', (size_t)spaces); |
3705 ptr += spaces; | 3705 ptr += spaces; |
3706 } | 3706 } |
3707 } | 3707 } |
3708 /* may insert some spaces after the new text */ | 3708 /* may insert some spaces after the new text */ |
3709 copy_spaces(ptr, (size_t)bd.endspaces); | 3709 vim_memset(ptr, ' ', (size_t)bd.endspaces); |
3710 ptr += bd.endspaces; | 3710 ptr += bd.endspaces; |
3711 /* move the text after the cursor to the end of the line. */ | 3711 /* move the text after the cursor to the end of the line. */ |
3712 mch_memmove(ptr, oldp + bd.textcol + delcount, | 3712 mch_memmove(ptr, oldp + bd.textcol + delcount, |
3713 (size_t)(oldlen - bd.textcol - delcount + 1)); | 3713 (size_t)(oldlen - bd.textcol - delcount + 1)); |
3714 ml_replace(curwin->w_cursor.lnum, newp, FALSE); | 3714 ml_replace(curwin->w_cursor.lnum, newp, FALSE); |
4520 cend -= currsize; | 4520 cend -= currsize; |
4521 mch_memmove(cend, curr, (size_t)currsize); | 4521 mch_memmove(cend, curr, (size_t)currsize); |
4522 if (spaces[t] > 0) | 4522 if (spaces[t] > 0) |
4523 { | 4523 { |
4524 cend -= spaces[t]; | 4524 cend -= spaces[t]; |
4525 copy_spaces(cend, (size_t)(spaces[t])); | 4525 vim_memset(cend, ' ', (size_t)(spaces[t])); |
4526 } | 4526 } |
4527 mark_col_adjust(curwin->w_cursor.lnum + t, (colnr_T)0, (linenr_T)-t, | 4527 mark_col_adjust(curwin->w_cursor.lnum + t, (colnr_T)0, (linenr_T)-t, |
4528 (long)(cend - newp + spaces[t] - (curr - curr_start))); | 4528 (long)(cend - newp + spaces[t] - (curr - curr_start))); |
4529 if (t == 0) | 4529 if (t == 0) |
4530 break; | 4530 break; |