aboutsummaryrefslogtreecommitdiff
path: root/runtime/lua/vim/shared.lua
diff options
context:
space:
mode:
authorJustin M. Keyes <justinkz@gmail.com>2021-09-10 07:05:11 -0700
committerGitHub <noreply@github.com>2021-09-10 07:05:11 -0700
commit7b822d4b4b71ef0e9ed6a39ef50a5a2cbf8660c5 (patch)
tree1e58317059af6850e9f06289f33fbb3f61d8cf63 /runtime/lua/vim/shared.lua
parentc7ccb26260e763cd5fde5f635da6889c736262fd (diff)
parent329047b3dbd09f7d77cdc07002c532c230e44ddb (diff)
downloadrneovim-7b822d4b4b71ef0e9ed6a39ef50a5a2cbf8660c5.tar.gz
rneovim-7b822d4b4b71ef0e9ed6a39ef50a5a2cbf8660c5.tar.bz2
rneovim-7b822d4b4b71ef0e9ed6a39ef50a5a2cbf8660c5.zip
Merge branch 'master' into histfile
Diffstat (limited to 'runtime/lua/vim/shared.lua')
-rw-r--r--runtime/lua/vim/shared.lua11
1 files changed, 8 insertions, 3 deletions
diff --git a/runtime/lua/vim/shared.lua b/runtime/lua/vim/shared.lua
index 032b2b2cb5..18c1e21049 100644
--- a/runtime/lua/vim/shared.lua
+++ b/runtime/lua/vim/shared.lua
@@ -267,18 +267,23 @@ function vim.tbl_deep_extend(behavior, ...)
end
--- Deep compare values for equality
+---
+--- Tables are compared recursively unless they both provide the `eq` methamethod.
+--- All other types are compared using the equality `==` operator.
+---@param a first value
+---@param b second value
+---@returns `true` if values are equals, else `false`.
function vim.deep_equal(a, b)
if a == b then return true end
if type(a) ~= type(b) then return false end
if type(a) == 'table' then
- -- TODO improve this algorithm's performance.
for k, v in pairs(a) do
if not vim.deep_equal(v, b[k]) then
return false
end
end
- for k, v in pairs(b) do
- if not vim.deep_equal(v, a[k]) then
+ for k, _ in pairs(b) do
+ if a[k] == nil then
return false
end
end