Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use string.buffer in OpenResty 1.21.4.1 #109

Merged
merged 2 commits into from
Jun 24, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions lib/resty/healthcheck.lua
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ local DEBUG = ngx.DEBUG
local ngx_log = ngx.log
local tostring = tostring
local ipairs = ipairs
local cjson = require("cjson.safe").new()
local table_insert = table.insert
local table_remove = table.remove
local resty_lock = require ("resty.lock")
Expand All @@ -50,6 +49,7 @@ local RESTY_WORKER_EVENTS_VER = "0.3.3"
local new_tab
local nkeys
local is_array
local codec

do
local pcall = pcall
Expand Down Expand Up @@ -85,6 +85,11 @@ do
return true
end
end

ok, codec = pcall(require, "string.buffer")
if not ok then
codec = require("cjson.safe").new()
end
end


Expand Down Expand Up @@ -228,17 +233,12 @@ local hcs = setmetatable({}, {

local active_check_timer

-- TODO: improve serialization speed
-- serialize a table to a string
local function serialize(t)
return cjson.encode(t)
end
local serialize = codec.encode


-- deserialize a string to a table
local function deserialize(s)
return cjson.decode(s)
end
local deserialize = codec.decode


local function key_for(key_prefix, ip, port, hostname)
Expand Down