aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorStefan Monnier2017-02-19 13:12:16 -0500
committerStefan Monnier2017-02-19 13:12:16 -0500
commit5c1ebfc504bc0649a9e1105b1d9265c461739254 (patch)
treeb6f7ec31424cf57f21a57beb2570e21d94387d83 /src
parentf03d936cd7a9e22f68c8ac1c14516d5079307b90 (diff)
downloademacs-5c1ebfc504bc0649a9e1105b1d9265c461739254.tar.gz
emacs-5c1ebfc504bc0649a9e1105b1d9265c461739254.zip
* src/insdel.c (make_gap): Increase enough to avoid O(N^2) behavior.
Diffstat (limited to 'src')
-rw-r--r--src/insdel.c15
1 files changed, 14 insertions, 1 deletions
diff --git a/src/insdel.c b/src/insdel.c
index 3f933b0ad85..8b684fd2780 100644
--- a/src/insdel.c
+++ b/src/insdel.c
@@ -560,7 +560,20 @@ void
560make_gap (ptrdiff_t nbytes_added) 560make_gap (ptrdiff_t nbytes_added)
561{ 561{
562 if (nbytes_added >= 0) 562 if (nbytes_added >= 0)
563 make_gap_larger (nbytes_added); 563 /* With set-buffer-multibyte on a large buffer, we can end up growing the
564 * buffer *many* times. Avoid an O(N^2) behavior by increasing by an
565 * amount at least proportional to the size of the buffer.
566 * On my test (a 223.9MB zip file on a Thinkpad T61):
567 * With /5 => 24s
568 * With /32 => 25s
569 * With /64 => 26s
570 * With /128 => 28s
571 * With /1024 => 51s
572 * With /4096 => 131s
573 * With /∞ => gave up after 858s
574 * Of couse, ideally we should never call set-buffer-multibyte on
575 * a non-empty buffer (e.g. use buffer-swa-text instead). */
576 make_gap_larger (max (nbytes_added, (Z - BEG) / 64));
564#if defined USE_MMAP_FOR_BUFFERS || defined REL_ALLOC || defined DOUG_LEA_MALLOC 577#if defined USE_MMAP_FOR_BUFFERS || defined REL_ALLOC || defined DOUG_LEA_MALLOC
565 else 578 else
566 make_gap_smaller (-nbytes_added); 579 make_gap_smaller (-nbytes_added);