Skip to content

faster cache_get #7

@level99

Description

@level99

Here is a faster version of cache_get. It removes a hash lookup which can take a decent toll on performance under a cache hit scenario. The gain is most noticeable if there are a fair number of params (eg. 3+).

local function cache_get(cache, params)
  local node = cache
  for i=1, #params do
    node = node and node.children
    node = node and node[params[i]]
  end
  return node and node.results or nil
end

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions