From 48162c4ee3fb013c09cecea52c6403a33526f172 Mon Sep 17 00:00:00 2001 From: Rob Landley Date: Mon, 6 May 2019 13:16:24 -0500 Subject: Greatly simplify and speed up regexec0() using REG_STARTEND. This is a 15 year old freebsd extension (presumably thus also available on MacOS) that glibc adopted in 2004, uClibc adopted in 2005, and bionic supports. The only thing that DOESN'T support it is musl, once again because its maintainer explicitly decided not to (https://www.openwall.com/lists/musl/2013/01/15/26), so add an #ifdef to let musl stay uniquely broken. (It'll stop at first NUL, everything else can match NULs). Finally fixes "s/x/y/g on a megabyte line of x's takes forever" issue. --- tests/sed.test | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'tests/sed.test') diff --git a/tests/sed.test b/tests/sed.test index 6b27fff8..e5ec11bd 100755 --- a/tests/sed.test +++ b/tests/sed.test @@ -176,4 +176,10 @@ testing '\n with empty capture' \ testing '\n too high' \ 'sed -E "s/(.*)/\2/p" 2>/dev/null || echo OK' "OK\n" "" "foo" +# Performance test +X=x; Y=20; while [ $Y -gt 0 ]; do X=$X$X; Y=$(($Y-1)); done +testing 'megabyte s/x/y/g (5 sec timeout)' "timeout 5 sed 's/x/y/g' | sha1sum" \ + '138c1fa7c3f64186203b0192fb4abdb33cb4e98a -\n' '' "$X\n" +unset X Y + # -i with $ last line test -- cgit v1.2.3