diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2020-11-13 16:52:20 +0000 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2020-11-13 16:52:20 +0000 |
commit | df5db936734ef1100bf31f0cb4fa0d2d1b4c70ed (patch) | |
tree | 823341b5750742f605df9669081d4ed081e5e4cb | |
parent | d4fa8bac0ab2e98168350c00a3053612d736d40d (diff) | |
download | rspamd-df5db936734ef1100bf31f0cb4fa0d2d1b4c70ed.tar.gz rspamd-df5db936734ef1100bf31f0cb4fa0d2d1b4c70ed.zip |
[Minor] Improve the default sort function in deep_sort function
-rw-r--r-- | lualib/lua_util.lua | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/lualib/lua_util.lua b/lualib/lua_util.lua index c4448117c..dadf3f3de 100644 --- a/lualib/lua_util.lua +++ b/lualib/lua_util.lua @@ -1012,10 +1012,18 @@ exports.deepcopy = deepcopy -- } -- Performs recursive in-place sort of a table --]] +local function default_sort_cmp(e1, e2) + if type(e1) == type(e2) then + return e1 < e2 + else + return type(e1) < type(e2) + end +end + local function deepsort(tbl, sort_func) local orig_type = type(tbl) if orig_type == 'table' then - table.sort(tbl, sort_func) + table.sort(tbl, sort_func or default_sort_cmp) for _, orig_value in next, tbl, nil do deepsort(orig_value) end |