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.
This commit is contained in:
Thomas Vigouroux
2022-09-07 08:39:56 +02:00
committed by GitHub
parent f32fd19f1e
commit fd1595514b
5 changed files with 69 additions and 10 deletions

View File

@@ -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).