| 975 | enum { CURSOR_LIVE = 1, CURSOR_BUSY = 2 }; |
| 976 | |
| 977 | TSTreeCursor *cbm_cursor_acquire(cbm_cursor_lease_t *lease, int depth, TSNode node) { |
| 978 | if (!tl_cursor_pool) { |
| 979 | tl_cursor_pool = cbm_calloc(CBM_MEM_CLASS_OTHER, sizeof(cursor_pool_t)); |
| 980 | } |
| 981 | cursor_pool_t *pool = tl_cursor_pool; |
| 982 | if (pool && depth >= 0 && depth < CURSOR_POOL_DEPTH && !(pool->state[depth] & CURSOR_BUSY)) { |
| 983 | if (pool->state[depth] & CURSOR_LIVE) { |
| 984 | ts_tree_cursor_reset(&pool->cursors[depth], node); |
| 985 | } else { |
| 986 | pool->cursors[depth] = ts_tree_cursor_new(node); |
| 987 | } |
| 988 | pool->state[depth] = CURSOR_LIVE | CURSOR_BUSY; |
| 989 | lease->slot = depth; |
| 990 | lease->cursor = &pool->cursors[depth]; |
| 991 | return lease->cursor; |
| 992 | } |
| 993 | /* No pool (or the slot is taken): a private cursor is always correct. */ |
| 994 | lease->private_cursor = ts_tree_cursor_new(node); |
| 995 | lease->slot = -1; |
| 996 | lease->cursor = &lease->private_cursor; |
| 997 | return lease->cursor; |
| 998 | } |
| 999 | |
| 1000 | void cbm_cursor_release(cbm_cursor_lease_t *lease) { |
| 1001 | if (lease->slot < 0) { |
no test coverage detected