Skip to content

Commit

Permalink
chore(vault): do not create substring in is_reference
Browse files Browse the repository at this point in the history
### Summary

Less pressure to garbage collector.

Signed-off-by: Aapo Talvensaari <aapo.talvensaari@gmail.com>
  • Loading branch information
bungle committed Aug 16, 2024
1 parent 030d674 commit fd53ac8
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions kong/pdk/vault.lua
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,11 @@ local BRACE_START = byte("{")
local BRACE_END = byte("}")
local COLON = byte(":")
local SLASH = byte("/")
local BYT_V = byte("v")
local BYT_A = byte("a")
local BYT_U = byte("u")
local BYT_L = byte("l")
local BYT_T = byte("t")


local VAULT_QUERY_OPTS = { workspace = ngx.null }
Expand All @@ -72,13 +77,17 @@ local VAULT_QUERY_OPTS = { workspace = ngx.null }
-- @tparam string reference reference to check
-- @treturn boolean `true` is the passed in reference looks like a reference, otherwise `false`
local function is_reference(reference)
return type(reference) == "string"
and byte(reference, 1) == BRACE_START
and byte(reference, -1) == BRACE_END
and byte(reference, 7) == COLON
and byte(reference, 8) == SLASH
and byte(reference, 9) == SLASH
and sub(reference, 2, 6) == "vault"
return type(reference) == "string"
and byte(reference, 1) == BRACE_START
and byte(reference, 2) == BYT_V
and byte(reference, 3) == BYT_A
and byte(reference, 4) == BYT_U
and byte(reference, 5) == BYT_L
and byte(reference, 6) == BYT_T
and byte(reference, 7) == COLON
and byte(reference, 8) == SLASH
and byte(reference, 9) == SLASH
and byte(reference, -1) == BRACE_END
end


Expand Down

0 comments on commit fd53ac8

Please sign in to comment.