CVSROOT: /cvs Module name: src Changes by: schwa...@cvs.openbsd.org 2011/07/24 07:59:15
Modified files: usr.bin/sed : process.c Log message: Rewrite the main loop of the "sed s/..." command, shortening it by ten lines and simplifying it by removing the switch statement implementing /g, /1, and /2 separately and repetitively. The idea to make the loop control variable slen, i.e. the length of the string remaining to be processed, signed, and stay in the loop even when slen == 0 (i.e. at the end of the string), lifted from FreeBSD by otto@. On i386, process.o shrinks by 440 bytes, and the sed binary by 23 bytes. This fixes multiple aspects of the replacement of multiple (/g) or specific (e.g. /2) instances of zero-length matches, both with BREs and EREs, both with and without a trailing newline character on the input. Feedback and OK otto@.