1 | #ifndef NVIM_MEMLINE_DEFS_H |
2 | #define NVIM_MEMLINE_DEFS_H |
3 | |
4 | #include "nvim/memfile_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 info_pointer { |
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 ml_chunksize { |
19 | int mlcs_numlines; |
20 | long 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 memline { |
44 | linenr_T ml_line_count; // number of lines in the buffer |
45 | |
46 | memfile_T *ml_mfp; // pointer to associated memfile |
47 | |
48 | #define ML_EMPTY 1 // empty buffer |
49 | #define ML_LINE_DIRTY 2 // cached line was changed and allocated |
50 | #define ML_LOCKED_DIRTY 4 // ml_locked was changed |
51 | #define ML_LOCKED_POS 8 // ml_locked needs positive block number |
52 | int ml_flags; |
53 | |
54 | infoptr_T *ml_stack; // stack of pointer blocks (array of IPTRs) |
55 | int ml_stack_top; // current top of ml_stack |
56 | int ml_stack_size; // total number of entries in ml_stack |
57 | |
58 | linenr_T ml_line_lnum; // line number of cached line, 0 if not valid |
59 | char_u *ml_line_ptr; // pointer to cached line |
60 | |
61 | bhdr_T *ml_locked; // block used by last ml_get |
62 | linenr_T ml_locked_low; // first line in ml_locked |
63 | linenr_T ml_locked_high; // last line in ml_locked |
64 | int ml_locked_lineadd; // number of lines inserted in ml_locked |
65 | chunksize_T *ml_chunksize; |
66 | int ml_numchunks; |
67 | int ml_usedchunks; |
68 | } memline_T; |
69 | |
70 | #endif // NVIM_MEMLINE_DEFS_H |
71 | |