Skip to content
This repository has been archived by the owner on Jul 23, 2019. It is now read-only.

Optimize cursor movement and selection manipulation #45

Merged
merged 5 commits into from Mar 16, 2018

Commits on Mar 15, 2018

  1. Use offset in insertion when creating and resolving anchors

    This fixes a logic error on master that uses `Anchor::offset` as an
    offset into the fragment. This is wrong because fragments could be
    subject to further splits, thus making the relative offset potentially
    invalid.
    Antonio Scandurra committed Mar 15, 2018
    Configuration menu
    Copy the full SHA
    f1361e8 View commit details
    Browse the repository at this point in the history
  2. Cache anchor positions until the buffer is edited

    This avoids unnecessary lookups in the buffer tree when the anchor's
    position has already been retrieved since the last edit.
    
    We are representing the cache as a RefCell to avoid the need to acquire
    a mutable reference to the buffer even if we just need to query it. If
    the cache is already borrowed for some reason, we will simply skip
    writing to it.
    Antonio Scandurra committed Mar 15, 2018
    Configuration menu
    Copy the full SHA
    cc7ce29 View commit details
    Browse the repository at this point in the history
  3. Wrap FragmentId's vector in a Rc

    This will allow to efficiently clone the FragmentId (i.e., without heap
    allocations) for comparison purposes when it's used during a tree
    traversal.
    Antonio Scandurra committed Mar 15, 2018
    Configuration menu
    Copy the full SHA
    a829f24 View commit details
    Browse the repository at this point in the history
  4. Use statically-allocated values for FragmentId min_value and max_value

    `lazy_static!` requires variables to be thread-safe (for good reasons),
    so we have also replaced `Rc` with an `Arc`. This doesn't seem to affect
    performance in a significant way.
    Antonio Scandurra committed Mar 15, 2018
    Configuration menu
    Copy the full SHA
    29b886e View commit details
    Browse the repository at this point in the history

Commits on Mar 16, 2018

  1. Cache mapping between offsets and points

    When moving cursors, we heavily rely on `Buffer::len_for_row` to
    understand when such cursors should wrap. This method is implemented by
    traversing the tree twice: the first traversal gets the offset of the
    beginning of the requested line, whereas the second traversal gets the
    offset of the line next to the requested one. Then, the two offsets are
    subtracted to obtain the length of the line.
    
    With this commit we start caching the mapping between offsets and
    points. This allows to skip the two traversals and retrieve the length
    of a line in constant time if the line length had been computed before
    and no edit has occurred since then.
    Antonio Scandurra committed Mar 16, 2018
    Configuration menu
    Copy the full SHA
    2d6c1b7 View commit details
    Browse the repository at this point in the history