optimize: use table.isarray to check whether table is an array. (#2365)

This commit is contained in:
Alex Zhang 2020-10-09 15:58:40 +08:00 committed by GitHub
parent 9d0d351226
commit 87a107ff4b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -17,7 +17,9 @@
local log = require("apisix.core.log") local log = require("apisix.core.log")
local profile = require("apisix.core.profile") local profile = require("apisix.core.profile")
local table = require("apisix.core.table")
local yaml = require("tinyyaml") local yaml = require("tinyyaml")
local io_open = io.open local io_open = io.open
local type = type local type = type
local str_gmatch = string.gmatch local str_gmatch = string.gmatch
@ -57,16 +59,6 @@ local function is_empty_yaml_line(line)
end end
local function tab_is_array(t)
local count = 0
for k,v in pairs(t) do
count = count + 1
end
return #t == count
end
local function tinyyaml_type(t) local function tinyyaml_type(t)
local mt = getmetatable(t) local mt = getmetatable(t)
if mt then if mt then
@ -84,7 +76,7 @@ local function merge_conf(base, new_tab, ppath)
if tinyyaml_type(val) == "null" then if tinyyaml_type(val) == "null" then
base[key] = nil base[key] = nil
elseif tab_is_array(val) then elseif table.isarray(val) then
base[key] = val base[key] = val
else else