neovim

Neovim text editor
git clone https://git.dasho.dev/neovim.git
Log | Files | Refs | README

memline_defs.h (2879B)


      1 #pragma once
      2 
      3 #include "nvim/memfile_defs.h"
      4 #include "nvim/pos_defs.h"
      5 
      6 ///
      7 /// When searching for a specific line, we remember what blocks in the tree
      8 /// are the branches leading to that block. This is stored in ml_stack.  Each
      9 /// entry is a pointer to info in a block (may be data block or pointer block)
     10 ///
     11 typedef struct {
     12  blocknr_T ip_bnum;            // block number
     13  linenr_T ip_low;              // lowest lnum in this block
     14  linenr_T ip_high;             // highest lnum in this block
     15  int ip_index;                 // index for block with current lnum
     16 } infoptr_T;    // block/index pair
     17 
     18 typedef struct {
     19  int mlcs_numlines;
     20  int mlcs_totalsize;
     21 } chunksize_T;
     22 
     23 // Flags when calling ml_updatechunk()
     24 #define ML_CHNK_ADDLINE 1
     25 #define ML_CHNK_DELLINE 2
     26 #define ML_CHNK_UPDLINE 3
     27 
     28 /// memline structure: the contents of a buffer.
     29 /// Essentially a tree with a branch factor of 128.
     30 /// Lines are stored at leaf nodes.
     31 /// Nodes are stored on ml_mfp (memfile_T):
     32 ///   pointer_block: internal nodes
     33 ///   data_block: leaf nodes
     34 ///
     35 /// Memline also has "chunks" of 800 lines that are separate from the 128-tree
     36 /// structure, primarily used to speed up line2byte() and byte2line().
     37 ///
     38 /// Motivation: If you have a file that is 10000 lines long, and you insert
     39 ///             a line at linenr 1000, you don't want to move 9000 lines in
     40 ///             memory.  With this structure it is roughly (N * 128) pointer
     41 ///             moves, where N is the height (typically 1-3).
     42 ///
     43 typedef struct {
     44  linenr_T ml_line_count;       // number of lines in the buffer
     45 
     46  memfile_T *ml_mfp;          // pointer to associated memfile
     47 
     48  infoptr_T *ml_stack;        // stack of pointer blocks (array of IPTRs)
     49  int ml_stack_top;             // current top of ml_stack
     50  int ml_stack_size;            // total number of entries in ml_stack
     51 
     52 #define ML_EMPTY        0x01    // empty buffer
     53 #define ML_LINE_DIRTY   0x02    // cached line was changed and allocated
     54 #define ML_LOCKED_DIRTY 0x04    // ml_locked was changed
     55 #define ML_LOCKED_POS   0x08    // ml_locked needs positive block number
     56 #define ML_ALLOCATED    0x10    // ml_line_ptr is an allocated copy
     57  int ml_flags;
     58 
     59  // colnr_T ml_line_len;
     60  colnr_T ml_line_textlen;      // length of the cached line + NUL
     61  linenr_T ml_line_lnum;        // line number of cached line, 0 if not valid
     62  char *ml_line_ptr;            // pointer to cached line
     63  size_t ml_line_offset;        // cached byte offset of ml_line_lnum
     64  int ml_line_offset_ff;        // fileformat of cached line
     65 
     66  bhdr_T *ml_locked;       // block used by last ml_get
     67  linenr_T ml_locked_low;       // first line in ml_locked
     68  linenr_T ml_locked_high;      // last line in ml_locked
     69  int ml_locked_lineadd;        // number of lines inserted in ml_locked
     70  chunksize_T *ml_chunksize;
     71  int ml_numchunks;
     72  int ml_usedchunks;
     73 } memline_T;