[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH] maint: optimize long-line processing
From: |
Jim Meyering |
Subject: |
[PATCH] maint: optimize long-line processing |
Date: |
Tue, 31 Jul 2012 21:44:17 +0200 |
FYI, when investigating the big-hole failure,
I noticed that its use of grep took 4.0s of user time and ~7s of system,
but with this change, the user-time component went down to 2.0 seconds
and the 7s stayed the same.
>From 8c74af84958634a22a24dbc7fecf3fafd3f8e4bd Mon Sep 17 00:00:00 2001
From: Jim Meyering <address@hidden>
Date: Mon, 30 Jul 2012 11:39:29 +0200
Subject: [PATCH] maint: optimize long-line processing
* src/main.c (grep): Use memrchr rather than an open-coded loop,
reducing the cost of the replaced code by 50% when processing very
long lines. If there were a rawmemrchr function (analogous to glibc's
rawmemchr), then the performance improvement would be even greater.
---
src/main.c | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/src/main.c b/src/main.c
index 84066d8..e3b5186 100644
--- a/src/main.c
+++ b/src/main.c
@@ -1200,8 +1200,10 @@ grep (int fd, struct stat const *st)
the buffer, 0 means there is no incomplete last line). */
oldc = beg[-1];
beg[-1] = eol;
- for (lim = buflim; lim[-1] != eol; lim--)
- continue;
+ /* FIXME: use rawmemrchr if/when it exists, since we have ensured
+ that this use of memrchr is guaranteed never to return NULL. */
+ lim = memrchr (beg - 1, eol, buflim - beg + 1);
+ ++lim;
beg[-1] = oldc;
if (lim == beg)
lim = beg - residue;
--
1.7.12.rc1
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [PATCH] maint: optimize long-line processing,
Jim Meyering <=