diff options
| author | Lars Ingebrigtsen | 2021-09-22 07:22:17 +0200 |
|---|---|---|
| committer | Lars Ingebrigtsen | 2021-09-22 07:22:22 +0200 |
| commit | f2bd2386a79fed311361fd9ca809ab1b2a0362a6 (patch) | |
| tree | c8c9d87316ac2fdb863763d03ef696ad814c40e5 /src | |
| parent | 7ce721bdacd65d47031060ee8e81d6117e94cc75 (diff) | |
| download | emacs-f2bd2386a79fed311361fd9ca809ab1b2a0362a6.tar.gz emacs-f2bd2386a79fed311361fd9ca809ab1b2a0362a6.zip | |
Speed up `replace-match' slightly
* src/search.c (Freplace_match): Speed up non-literal (but
actually literal) common case.
This makes
(benchmark-run 1000000
(replace-regexp-in-string
"a+" "foo"
"ogihdipofdhookfdohkfdpokhpokhfdpokfdhpokfdhkdfkhgoadfphokfkhpofdkhkdpokf"))
about 10% faster.
Diffstat (limited to 'src')
| -rw-r--r-- | src/search.c | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/src/search.c b/src/search.c index 14adeb58e96..08f1e9474f1 100644 --- a/src/search.c +++ b/src/search.c | |||
| @@ -2387,6 +2387,13 @@ since only regular expressions have distinguished subexpressions. */) | |||
| 2387 | if (! NILP (string)) | 2387 | if (! NILP (string)) |
| 2388 | CHECK_STRING (string); | 2388 | CHECK_STRING (string); |
| 2389 | 2389 | ||
| 2390 | /* Most replacement texts don't contain any backslash directives in | ||
| 2391 | the replacements. Check whether that's the case, which will | ||
| 2392 | enable us to take the fast path later. */ | ||
| 2393 | if (NILP (literal) | ||
| 2394 | && !memchr (SSDATA (newtext), '\\', SBYTES (newtext))) | ||
| 2395 | literal = Qt; | ||
| 2396 | |||
| 2390 | case_action = nochange; /* We tried an initialization */ | 2397 | case_action = nochange; /* We tried an initialization */ |
| 2391 | /* but some C compilers blew it */ | 2398 | /* but some C compilers blew it */ |
| 2392 | 2399 | ||