To: vim-dev@vim.org Subject: Patch 5.6.040 Fcc: outbox From: Bram Moolenaar ------------ Patch 5.6.040 Problem: When using ":s" command, matching the regexp is done twice. Solution: After copying the matched line, adjust the pointers instead of finding the match again. (Loic Grenie) Added vim_regnewptr(). Files: src/ex_cmds.c, src/regexp.c, src/proto/regexp.pro *** ../vim-5.6.39/src/ex_cmds.c Sat Mar 25 18:13:49 2000 --- src/ex_cmds.c Thu Mar 30 09:46:28 2000 *************** *** 3185,3197 **** unsigned len, needed_len; unsigned new_start_len = 0; ! /* make a copy of the line, so it won't be taken away when updating ! the screen */ if ((old_line = vim_strsave(ptr)) == NULL) continue; ! vim_regexec(prog, old_line, TRUE); /* match again on this line to ! * update the pointers. TODO: ! * remove extra vim_regexec() */ if (!got_match) { setpcmark(); --- 3185,3197 ---- unsigned len, needed_len; unsigned new_start_len = 0; ! /* Make a copy of the line, so it won't be taken away when ! * updating the screen. */ if ((old_line = vim_strsave(ptr)) == NULL) continue; ! /* Adjust the pointers in "prog" for the copied string. */ ! vim_regnewptr(prog, ptr, old_line); ! if (!got_match) { setpcmark(); *** ../vim-5.6.39/src/regexp.c Sat May 15 15:48:51 1999 --- src/regexp.c Thu Mar 30 09:59:23 2000 *************** *** 2954,2959 **** --- 2954,2982 ---- } /* + * Adjust the pointers in "prog" for moving the matches text from "old_ptr" to + * "new_ptr". Used when saving a copy of the matched text and want to use + * vim_regsub(). + */ + void + vim_regnewptr(prog, old_ptr, new_ptr) + vim_regexp *prog; + char_u *old_ptr; + char_u *new_ptr; + { + int j; + long off = new_ptr - old_ptr; + + for (j = 0; j < NSUBEXP; ++j) + { + if (prog->startp[j] != NULL) + prog->startp[j] += off; + if (prog->endp[j] != NULL) + prog->endp[j] += off; + } + } + + /* * vim_regsub() - perform substitutions after a regexp match * * If copy is TRUE really copy into dest. *** ../vim-5.6.39/src/proto/regexp.pro Sun Jan 16 14:22:52 2000 --- src/proto/regexp.pro Thu Mar 30 10:02:07 2000 *************** *** 4,7 **** --- 4,8 ---- int vim_regcomp_had_eol __ARGS((void)); int vim_regexec __ARGS((vim_regexp *prog, char_u *string, int at_bol)); char_u *regtilde __ARGS((char_u *source, int magic)); + void vim_regnewptr __ARGS((vim_regexp *prog, char_u *old_ptr, char_u *new_ptr)); int vim_regsub __ARGS((vim_regexp *prog, char_u *source, char_u *dest, int copy, int magic)); *** ../vim-5.6.39/src/version.c Wed Mar 29 12:35:54 2000 --- src/version.c Thu Mar 30 15:59:30 2000 *************** *** 420,421 **** --- 420,423 ---- { /* Add new patch number below this line */ + /**/ + 40, /**/ -- CONCORDE: Quickly, sir, come this way! LAUNCELOT: No! It's not right for my idiom. I must escape more ... more ... CONCORDE: Dramatically, sir? LAUNCELOT: Dramatically. "Monty Python and the Holy Grail" PYTHON (MONTY) PICTURES LTD /-/-- Bram Moolenaar --- Bram@moolenaar.net --- http://www.moolenaar.net --\-\ \-\-- Vim: http://www.vim.org ---- ICCF Holland: http://www.vim.org/iccf --/-/