aboutsummaryrefslogtreecommitdiff
path: root/runtime/lua/vim/treesitter/query.lua
diff options
context:
space:
mode:
authorThomas Vigouroux <thomas.vigouroux@protonmail.com>2022-09-07 08:39:56 +0200
committerGitHub <noreply@github.com>2022-09-07 08:39:56 +0200
commitfd1595514b747d8b083f78007579d869ccfbe89c (patch)
tree41e52c9e43db9351de3aa33a8628b76db07906c3 /runtime/lua/vim/treesitter/query.lua
parentf32fd19f1eedbd75e6a37b73f28cf8761e0e875c (diff)
downloadrneovim-fd1595514b747d8b083f78007579d869ccfbe89c.tar.gz
rneovim-fd1595514b747d8b083f78007579d869ccfbe89c.tar.bz2
rneovim-fd1595514b747d8b083f78007579d869ccfbe89c.zip
Use weak tables in tree-sitter code (#17117)
feat(treesitter): use weak tables when possible Also add the defaulttable function to create a table whose values are created when a key is missing.
Diffstat (limited to 'runtime/lua/vim/treesitter/query.lua')
-rw-r--r--runtime/lua/vim/treesitter/query.lua9
1 files changed, 3 insertions, 6 deletions
diff --git a/runtime/lua/vim/treesitter/query.lua b/runtime/lua/vim/treesitter/query.lua
index 697e2e7691..78042a74bf 100644
--- a/runtime/lua/vim/treesitter/query.lua
+++ b/runtime/lua/vim/treesitter/query.lua
@@ -140,12 +140,9 @@ function M.get_query(lang, query_name)
end
end
-local query_cache = setmetatable({}, {
- __index = function(tbl, key)
- rawset(tbl, key, {})
- return rawget(tbl, key)
- end,
-})
+local query_cache = vim.defaulttable(function()
+ return setmetatable({}, { __mode = 'v' })
+end)
--- Parse {query} as a string. (If the query is in a file, the caller
--- should read the contents into a string before calling).