]> code.delx.au - gnu-emacs/commitdiff
Speed up keyboard auto-repeat cursor motion under bidi redisplay.
authorEli Zaretskii <eliz@gnu.org>
Sat, 23 Jul 2011 07:42:56 +0000 (10:42 +0300)
committerEli Zaretskii <eliz@gnu.org>
Sat, 23 Jul 2011 07:42:56 +0000 (10:42 +0300)
 src/xdisp.c (compute_stop_pos_backwards): New function.
 (next_element_from_buffer): Call compute_stop_pos_backwards to
 find a suitable prev_stop when we find ourselves before
 base_level_stop.
 (reseat): Don't look for prev_stop, as that could mean a very long
 run.
 <cached_disp_pos, cached_disp_buffer, cached_disp_modiff>
 <cached_disp_overlay_modiff>: Cache for last found display string
 position.
 (compute_display_string_pos): Return the cached position if asked
 about the same buffer in the same area of character positions, and
 the buffer wasn't changed since the time the display string
 position was cached.

1  2 
src/ChangeLog
src/xdisp.c

diff --cc src/ChangeLog
index 0b06e5bf2c058f67a0b0c0dc5cc0d3bea4c16af4,c03acbcfd1c6e09ae28bc091c069bdc46d3760a3..ef60506e7242591b4c9f8fa99aedcd6f2fa948af
 -      (handle_stop_backwards): Revert last change.
+ 2011-07-22  Eli Zaretskii  <eliz@gnu.org>
++      Fix a significant slow-down of cursor motion with C-n, C-p,
++      C-f/C-b, and C-v/M-v that couldn't keep up with keyboard
++      auto-repeat under bidi redisplay in fontified buffers.
+       * xdisp.c (compute_stop_pos_backwards): New function.
 -      base_level_stop.  Remove the funky search for 1000 character
 -      positions back.
 -
 -2011-07-19  Eli Zaretskii  <eliz@gnu.org>
 -
 -      Fix a significant slow-down of vertical-motion when leaning on C-n
 -      or C-p in a fontified buffer.
 -      * xdisp.c (reseat): Don't look for prev_stop, as that could mean a
 -      very long run.
 -      (next_element_from_buffer): When iterator oversteps prev_pos
 -      backwards, don't search for a new prev_stop more than 1000
 -      characters back.
 -      (handle_stop_backwards): Don't assume that CHARPOS is necessarily
 -      a stop_pos.
 -      (compute_display_string_pos): Check also BUF_OVERLAY_MODIFF for a
 -      match, when testing the cached display string position for
 -      applicability.
 -
 -2011-07-16  Eli Zaretskii  <eliz@gnu.org>
 -
 -      * xdisp.c <cached_disp_pos, cached_disp_buffer, cached_disp_modiff>:
 -      Cache for last found display string position.
+       (next_element_from_buffer): Call compute_stop_pos_backwards to
+       find a suitable prev_stop when we find ourselves before
 -      about the same buffer.
++      base_level_stop.
++      (reseat): Don't look for prev_stop, as that could mean a very long
++      run.
++      <cached_disp_pos, cached_disp_buffer, cached_disp_modiff>
++      <cached_disp_overlay_modiff>: Cache for last found display string
++      position.
+       (compute_display_string_pos): Return the cached position if asked
 -2011-07-14  Eli Zaretskii  <eliz@gnu.org>
++      about the same buffer in the same area of character positions, and
++      the buffer wasn't changed since the time the display string
++      position was cached.
 +2011-07-22  Eli Zaretskii  <eliz@gnu.org>
  
 -      * bidi.c (bidi_cache_fetch_state, bidi_cache_search)
 -      (bidi_cache_find_level_change, bidi_cache_ensure_space)
 -      (bidi_cache_iterator_state, bidi_cache_find)
 -      (bidi_find_other_level_edge, bidi_cache_start_stack): All
 -      variables related to cache indices are now EMACS_INT.
 +      * xdisp.c (rows_from_pos_range): Don't ignore glyphs whose object
 +      is an integer, which is important for empty lines.  (Bug#9149)
  
 -2011-07-09  Eli Zaretskii  <eliz@gnu.org>
 +2011-07-22  Chong Yidong  <cyd@stupidchicken.com>
  
 -      * bidi.c (bidi_fetch_char): Fix the type of `len' according to
 -      what STRING_CHAR_AND_LENGTH expects.
 +      * frame.c (Fmodify_frame_parameters): In tty case, update the
 +      default face if necessary (Bug#4238).
  
 -      * xdisp.c (move_it_in_display_line_to): Record prev_method and
 -      prev_pos immediately before the call to set_iterator_to_next.
 -      Fixes cursor motion in bidi-reordered lines with stretch glyphs
 -      and strings displayed in margins.  (Bug#8133)  (Bug#8867)
 -      Return MOVE_POS_MATCH_OR_ZV only if iterator position is past
 -      TO_CHARPOS.
 -      (pos_visible_p): Support positions in bidi-reordered lines.  Save
 -      and restore bidi cache.
 +2011-07-21  Chong Yidong  <cyd@stupidchicken.com>
  
 -2011-07-08  Eli Zaretskii  <eliz@gnu.org>
 +      * editfns.c (Fstring_to_char): No need to explain what a character
 +      is in the docstring (Bug#6576).
  
 -      * xdisp.c (move_it_in_display_line_to): If iterator ended up at
 -      EOL, but we never saw any buffer positions smaller than
 -      to_charpos, return MOVE_POS_MATCH_OR_ZV.  Fixes vertical cursor
 -      motion in bidi-reordered lines.
 +2011-07-20  Lars Magne Ingebrigtsen  <larsi@gnus.org>
  
 -2011-07-07  Eli Zaretskii  <eliz@gnu.org>
 +      * xml.c (parse_region): Make sure we always return a tree.
  
 -      * xdisp.c (find_row_edges): If ROW->start.pos gives position
 -      smaller than min_pos, use it as ROW->minpos.  (Bug#7616)
 +2011-07-20  HAMANO Kiyoto  <khiker.mail@gmail.com>
  
 -2011-07-05  Eli Zaretskii  <eliz@gnu.org>
 +      * xml.c (parse_region): If a document contains only comments,
 +      return that, too.
  
 -      * dispnew.c (buffer_posn_from_coords): Save and restore the bidi
 -      cache around display iteration.
 +2011-07-20  Lars Magne Ingebrigtsen  <larsi@gnus.org>
  
 -      * window.c (Fwindow_end, window_scroll_pixel_based)
 -      (displayed_window_lines, Frecenter): Save and restore the bidi
 -      cache around display iteration.
 +      * xml.c (make_dom): Return comments, too.
  
 -      * bidi.c (bidi_unshelve_cache): Ensure we have enough space before
 -      restoring the shelved cache.
 -      (bidi_cache_ensure_space): Don't assume the required size is just
 -      one BIDI_CACHE_CHUNK away.
 +2011-07-19  Paul Eggert  <eggert@cs.ucla.edu>
  
 -      * xdisp.c (back_to_previous_visible_line_start, reseat_1)
 -      (init_iterator): Empty the bidi cache "stack".
 +      Port to OpenBSD.
 +      See http://lists.gnu.org/archive/html/emacs-devel/2011-07/msg00688.html
 +      and the surrounding thread.
 +      * minibuf.c (read_minibuf_noninteractive): Rewrite to use getchar
 +      rather than fgets, and retry after EINTR.  Otherwise, 'emacs
 +      --batch -f byte-compile-file' fails on OpenBSD if an inactivity
 +      timer goes off.
 +      * s/openbsd.h (BROKEN_SIGIO): Define.
 +      * unexelf.c (unexec) [__OpenBSD__]:
 +      Don't update the .mdebug section of the Alpha COFF symbol table.
  
 -2011-07-03  Eli Zaretskii  <eliz@gnu.org>
 +2011-07-19  Lars Magne Ingebrigtsen  <larsi@gnus.org>
  
 -      * bidi.c (bidi_shelve_cache, bidi_unshelve_cache): New functions.
 +      * lread.c (syms_of_lread): Clarify when `lexical-binding' is used
 +      (bug#8460).
  
 -      * dispextern.h (bidi_shelve_cache, bidi_unshelve_cache): Declare
 -      prototypes.
 +2011-07-18  Paul Eggert  <eggert@cs.ucla.edu>
  
 -      * xdisp.c (SAVE_IT, RESTORE_IT): New macros.
 -      (pos_visible_p, face_before_or_after_it_pos)
 -      (back_to_previous_visible_line_start)
 -      (move_it_in_display_line_to, move_it_in_display_line)
 -      (move_it_to, move_it_vertically_backward, move_it_by_lines)
 -      (try_scrolling, redisplay_window, display_line): Use them when
 -      saving a temporary copy of the iterator and restoring it back.
 +      * fileio.c (Fcopy_file) [!MSDOS]: Tighten created file's mask.
 +      This fixes some race conditions on the permissions of any newly
 +      created file.
  
 -2011-07-02  Eli Zaretskii  <eliz@gnu.org>
 +      * alloc.c (valid_pointer_p): Use pipe, not open.
 +      This fixes some permissions issues when debugging.
  
 -      * xdisp.c (reseat_1): Call bidi_init_it to resync the bidi
 -      iterator with IT's position.  (Bug#7616)
 -      (handle_stop, back_to_previous_visible_line_start, reseat_1):
 -      Reset the from_disp_prop_p flag.
 +      * fileio.c (Fcopy_file): Adjust mode if fchown fails.  (Bug#9002)
 +      If fchown fails to set both uid and gid, try to set just gid,
 +      as that is sometimes allowed.  Adjust the file's mode to eliminate
 +      setuid or setgid bits that are inappropriate if fchown fails.
  
 -      * bidi.c (bidi_cache_search): Don't assume bidi_cache_last_idx is
 -      always valid if bidi_cache_idx is valid.
 -      (bidi_cache_find_level_change): xassert that bidi_cache_last_idx
 -      is valid if it's going to be used.
 +2011-07-18  Stefan Monnier  <monnier@iro.umontreal.ca>
 +
 +      * xdisp.c (next_element_from_string, next_element_from_buffer): Use EQ
 +      to compare Lisp_Objects.
 +      * gnutls.c (syms_of_gnutls): Rename Vgnutls_log_level to
 +      global_gnutls_log_level, don't mistake it for a Lisp_Object.
 +      (init_gnutls_functions, emacs_gnutls_handle_error): Fix up uses.
 +
 +2011-07-17  Andreas Schwab  <schwab@linux-m68k.org>
 +
 +      * lread.c (read_integer): Unread even EOF character.
 +      (read1): Likewise.  Properly record start position of symbol.
  
 -      * dispextern.h (struct iterator_stack_entry, struct it): New
 -      member from_disp_prop_p.
 +      * lread.c (read1): Read `#:' as empty uninterned symbol if no
 +      symbol character follows.
  
 -      * xdisp.c (push_it, pop_it): Save and restore from_disp_prop_p.
 +2011-07-17  Paul Eggert  <eggert@cs.ucla.edu>
 +
 +      * fileio.c (Fcopy_file): Pacify gcc re fchown.  (Bug#9002)
 +      This works around a problem with the previous change to Fcopy_file.
 +      Recent glibc declares fchown with __attribute__((warn_unused_result)),
 +      and without this change, GCC might complain about discarding
 +      fchown's return value.
 +
 +2011-07-16  Juanma Barranquero  <lekktu@gmail.com>
 +
 +      * makefile.w32-in (GLOBAL_SOURCES): Add gnutls.c (followup to bug#9059).
 +
 +2011-07-16  Paul Eggert  <eggert@cs.ucla.edu>
 +
 +      * fileio.c (Fcopy_file): Don't diagnose fchown failures.  (Bug#9002)
 +
 +2011-07-16  Lars Magne Ingebrigtsen  <larsi@gnus.org>
 +
 +      * gnutls.c (syms_of_gnutls): Define `gnutls-log-level' here, since
 +      it's used from the C level.
 +
 +      * process.c: Use the same condition for POLL_FOR_INPUT in both
 +      keyboard.c and process.c (bug#1858).
 +
 +2011-07-09  Lawrence Mitchell  <wence@gmx.li>
 +
 +      * gnutls.c (Qgnutls_bootprop_min_prime_bits): New variable.
 +      (Fgnutls_boot): Use it.
 +
 +2011-07-15  Andreas Schwab  <schwab@linux-m68k.org>
 +
 +      * doc.c (Fsubstitute_command_keys): Revert last change.
 +
 +2011-07-15  Lars Magne Ingebrigtsen  <larsi@gnus.org>
 +
 +      * doc.c (Fsubstitute_command_keys): Clarify that \= really only
 +      quotes the next character, and doesn't affect other longer
 +      sequences (bug#8935).
 +
 +      * lread.c (syms_of_lread): Clarify that is isn't only
 +      `eval-buffer' and `eval-defun' that's affected by
 +      `lexical-binding' (bug#8460).
 +
 +2011-07-15  Eli Zaretskii  <eliz@gnu.org>
 +
 +      * xdisp.c (move_it_in_display_line_to): Fix vertical motion with
 +      bidi redisplay when a line includes both an image and is
 +      truncated.
 +
 +2011-07-14  Paul Eggert  <eggert@cs.ucla.edu>
 +
 +      Fix minor problems found by static checking.
 +      * bidi.c (bidi_cache_size): Now EMACS_INT, not size_t.
 +      (elsz): Now a signed constant, not a size_t var.  We prefer signed
 +      types to unsigned, to avoid integer comparison confusion.  Without
 +      this change, GCC 4.6.1 with -Wunsafe-loop-optimizations complains
 +      "cannot optimize loop, the loop counter may overflow", a symptom
 +      of the confusion.
 +      * indent.c (Fvertical_motion): Mark locals as initialized.
 +      * xdisp.c (reseat_to_string): Fix pointer signedness issue.
 +
 +2011-07-14  Lars Magne Ingebrigtsen  <larsi@gnus.org>
 +
 +      * search.c (Fre_search_backward): Mention `case-fold-search' in
 +      all the re_search_* functions (bug#8138).
 +
 +      * keyboard.c (Fopen_dribble_file): Document when the file is
 +      closed (bug#8056).
 +
 +2011-07-14  Eli Zaretskii  <eliz@gnu.org>
 +
 +      * bidi.c (bidi_dump_cached_states): Fix format of displaying
 +      bidi_cache_idx.
 +
 +      Support bidi reordering of display and overlay strings.
 +      * xdisp.c (compute_display_string_pos)
 +      (compute_display_string_end): Accept additional argument STRING.
 +      (init_iterator, reseat_1): Initialize bidi_it->string.s to NULL.
 +      (reseat_to_string): Initialize bidi_it->string.s and
 +      bidi_it->string.schars.
 +      (Fcurrent_bidi_paragraph_direction): Initialize itb.string.s to
 +      NULL (avoids a crash in bidi_paragraph_init).  Initialize
 +      itb.string.lstring.
 +      (init_iterator): Call bidi_init_it only of a valid
 +      buffer position was specified.  Initialize paragraph_embedding to
 +      L2R.
 +      (reseat_to_string): Initialize the bidi iterator.
 +      (display_string): If we need to ignore text properties of
 +      LISP_STRING, set IT->stop_charpos to IT->end_charpos.  (The
 +      original value of -1 will not work with bidi.)
 +      (compute_display_string_pos): First arg is now struct
 +      `text_pos *'; all callers changed.  Support display properties on
 +      Lisp strings.
 +      (compute_display_string_end): Support display properties on Lisp
 +      strings.
 +      (init_iterator, reseat_1, reseat_to_string): Initialize the
 +      string.bufpos member to 0 (zero, for compatibility with IT_CHARPOS
 +      when iterating on a string not from display properties).
 +      (compute_display_string_pos, compute_display_string_end): Fix
 +      calculation of the object to scan.  Fixes an error when using
 +      arrow keys.
 +      (next_element_from_buffer): Don't abort when IT_CHARPOS is before
 +      base_level_stop; instead, set base_level_stop to BEGV.  Fixes
 +      crashes in vertical-motion.
 +      (next_element_from_buffer): Improve commentary for when
 +      the iterator is before prev_stop.
 +      (init_iterator): Initialize bidi_p from the default value of
 +      bidi-display-reordering, not from buffer-local value.  Use the
 +      buffer-local value only if initializing for buffer iteration.
 +      (handle_invisible_prop): Support invisible properties on strings
 +      that are being bidi-reordered.
 +      (set_iterator_to_next): Support bidi reordering of C strings and
 +      Lisp strings.
 +      (next_element_from_string): Support bidi reordering of Lisp
 +      strings.
 +      (handle_stop_backwards): Support Lisp strings as well.
 +      (display_string): Support display of R2L glyph rows.  Use
 +      IT_STRING_CHARPOS when displaying from a Lisp string.
 +      (init_iterator): Don't initialize it->bidi_p for strings
 +      here.
 +      (reseat_to_string): Initialize it->bidi_p for strings here.
 +      (next_element_from_string, next_element_from_c_string)
 +      (next_element_from_buffer): Add xassert's for correspondence
 +      between IT's object being iterated and it->bidi_it.string
 +      structure.
 +      (face_before_or_after_it_pos): Support bidi iteration.
 +      (next_element_from_c_string): Handle the case of the first string
 +      character that is not the first one in the visual order.
 +      (get_visually_first_element): New function, refactored from common
 +      parts of next_element_from_buffer, next_element_from_string, and
 +      next_element_from_c_string.
 +      (tool_bar_lines_needed, redisplay_tool_bar)
 +      (display_menu_bar): Force left-to-right direction.  Add a FIXME
 +      comment for making that be controlled by a user option.
 +      (push_it, pop_it): Save and restore the state of the
 +      bidi iterator.  Save and restore the bidi_p flag.
 +      (pop_it): Iterate out of display property for string iteration as
 +      well.
 +      (iterate_out_of_display_property): Support iteration over strings.
 +      (handle_single_display_spec): Set up it->bidi_it for iteration
 +      over a display string, and call bidi_init_it.
 +      (handle_single_display_spec, next_overlay_string)
 +      (get_overlay_strings_1, push_display_prop): Set up the bidi
 +      iterator for displaying display or overlay strings.
 +      (forward_to_next_line_start): Don't use the shortcut if
 +      bidi-iterating.
 +      (back_to_previous_visible_line_start): If handle_display_prop
 +      pushed the iterator stack, restore the internal state of the bidi
 +      iterator by calling bidi_pop_it same number of times.
 +      (reseat_at_next_visible_line_start): If ON_NEWLINE_P is non-zero,
 +      and we are bidi-iterating, don't decrement the iterator position;
 +      instead, set the first_elt flag in the bidi iterator, to produce
 +      the same effect.
 +      (reseat_1): Remove redundant setting of string_from_display_prop_p.
 +      (push_display_prop): xassert that we are iterating a buffer.
 +      (push_it, pop_it): Save and restore paragraph_embedding member.
 +      (handle_single_display_spec, next_overlay_string)
 +      (get_overlay_strings_1, reseat_1, reseat_to_string)
 +      (push_display_prop): Set up the `unibyte' member of bidi_it.string
 +      correctly.  Don't assume unibyte strings are not bidi-reordered.
 +      (compute_display_string_pos)
 +      (compute_display_string_end): Fix handling the case of C string.
 +      (push_it, pop_it): Save and restore from_disp_prop_p.
        (handle_single_display_spec, push_display_prop): Set the
        from_disp_prop_p flag.
        (get_overlay_strings_1): Reset the from_disp_prop_p flag.
diff --cc src/xdisp.c
index 905a7ecbf8f76eb67f519abceb066c10fd8845a3,52b1f484939d7e105988634f3b518cda45eff80b..4075688ea0a74e071a7456d2e9c2c1e3646bfea9
@@@ -3134,6 -3137,16 +3134,14 @@@ next_overlay_change (EMACS_INT pos
    return endpos;
  }
  
 -static int ignore_display_strings;
 -
+ /* Record one cached display string position found recently by
+    compute_display_string_pos.  */
+ static EMACS_INT cached_disp_pos;
+ static EMACS_INT cached_prev_pos;
+ static struct buffer *cached_disp_buffer;
+ static int cached_disp_modiff;
+ static int cached_disp_overlay_modiff;
  /* Return the character position of a display string at or after
     position specified by POSITION.  If no display string exists at or
     after POSITION, return ZV.  A display string is either an overlay
@@@ -3161,9 -3175,37 +3170,36 @@@ compute_display_string_pos (struct text
         that have display string properties.  */
        || string->from_disp_str
        /* C strings cannot have display properties.  */
 -      || (string->s && !STRINGP (object))
 -      || ignore_display_strings)
 +      || (string->s && !STRINGP (object)))
      return eob;
  
+   /* Check the cached values.  */
+   if (!STRINGP (object))
+     {
+       if (NILP (object))
+       b = current_buffer;
+       else
+       b = XBUFFER (object);
+       if (b == cached_disp_buffer
+         && BUF_MODIFF (b) == cached_disp_modiff
+         && BUF_OVERLAY_MODIFF (b) == cached_disp_overlay_modiff)
+       {
+         if (cached_prev_pos
+             && cached_prev_pos < charpos && charpos <= cached_disp_pos)
+           return cached_disp_pos;
+         /* Handle overstepping either end of the known interval.  */
+         if (charpos > cached_disp_pos)
+           cached_prev_pos = cached_disp_pos;
+         else  /* charpos <= cached_prev_pos */
+           cached_prev_pos = max (charpos - 1, BEGV);
+       }
+       /* Record new values in the cache.  */
+       cached_disp_buffer = b;
+       cached_disp_modiff = BUF_MODIFF (b);
+       cached_disp_overlay_modiff = BUF_OVERLAY_MODIFF (b);
+     }
    /* If the character at CHARPOS is where the display string begins,
       return CHARPOS.  */
    pos = make_number (charpos);
@@@ -5731,17 -5773,11 +5773,19 @@@ reseat (struct it *it, struct text_pos 
        {
          /* For bidi iteration, we need to prime prev_stop and
             base_level_stop with our best estimations.  */
-         if (CHARPOS (pos) < it->prev_stop)
-           {
-             handle_stop_backwards (it, BEGV);
-             if (CHARPOS (pos) < it->base_level_stop)
-               it->base_level_stop = 0;
-           }
-         else if (CHARPOS (pos) > it->stop_charpos
-                  && it->stop_charpos >= BEGV)
-           handle_stop_backwards (it, it->stop_charpos);
-         else  /* force_p */
-           handle_stop (it);
++        /* Implementation note: Of course, POS is not necessarily a
++           stop position, so assigning prev_pos to it is a lie; we
++           should have called compute_stop_backwards.  However, if
++           the current buffer does not include any R2L characters,
++           that call would be a waste of cycles, because the
++           iterator will never move back, and thus never cross this
++           "fake" stop position.  So we delay that backward search
++           until the time we really need it, in next_element_from_buffer.  */
+         if (CHARPOS (pos) != it->prev_stop)
+           it->prev_stop = CHARPOS (pos);
+         if (CHARPOS (pos) < it->base_level_stop)
 -          it->base_level_stop = 0;
++          it->base_level_stop = 0; /* meaning it's unknown */
+         handle_stop (it);
        }
        else
        {