refactor: small perf win by eliminating string object keys
This commit is contained in:
parent
db60c32d93
commit
4a4e0f4013
12 changed files with 151 additions and 111 deletions
|
|
@ -1,13 +1,16 @@
|
|||
local cache = require("oil.cache")
|
||||
local columns = require("oil.columns")
|
||||
local config = require("oil.config")
|
||||
local constants = require("oil.constants")
|
||||
local fs = require("oil.fs")
|
||||
local permissions = require("oil.adapters.files.permissions")
|
||||
local trash = require("oil.adapters.files.trash")
|
||||
local util = require("oil.util")
|
||||
local FIELD = require("oil.constants").FIELD
|
||||
local M = {}
|
||||
|
||||
local FIELD_NAME = constants.FIELD_NAME
|
||||
local FIELD_META = constants.FIELD_META
|
||||
|
||||
local function read_link_data(path, cb)
|
||||
vim.loop.fs_readlink(
|
||||
path,
|
||||
|
|
@ -44,7 +47,7 @@ local fs_stat_meta_fields = {
|
|||
stat = function(parent_url, entry, cb)
|
||||
local _, path = util.parse_url(parent_url)
|
||||
local dir = fs.posix_to_os_path(path)
|
||||
vim.loop.fs_stat(fs.join(dir, entry[FIELD.name]), cb)
|
||||
vim.loop.fs_stat(fs.join(dir, entry[FIELD_NAME]), cb)
|
||||
end,
|
||||
}
|
||||
|
||||
|
|
@ -52,7 +55,7 @@ file_columns.size = {
|
|||
meta_fields = fs_stat_meta_fields,
|
||||
|
||||
render = function(entry, conf)
|
||||
local meta = entry[FIELD.meta]
|
||||
local meta = entry[FIELD_META]
|
||||
local stat = meta.stat
|
||||
if not stat then
|
||||
return ""
|
||||
|
|
@ -79,7 +82,7 @@ if not fs.is_windows then
|
|||
meta_fields = fs_stat_meta_fields,
|
||||
|
||||
render = function(entry, conf)
|
||||
local meta = entry[FIELD.meta]
|
||||
local meta = entry[FIELD_META]
|
||||
local stat = meta.stat
|
||||
if not stat then
|
||||
return ""
|
||||
|
|
@ -92,7 +95,7 @@ if not fs.is_windows then
|
|||
end,
|
||||
|
||||
compare = function(entry, parsed_value)
|
||||
local meta = entry[FIELD.meta]
|
||||
local meta = entry[FIELD_META]
|
||||
if parsed_value and meta.stat and meta.stat.mode then
|
||||
local mask = bit.lshift(1, 12) - 1
|
||||
local old_mode = bit.band(meta.stat.mode, mask)
|
||||
|
|
@ -135,7 +138,7 @@ for _, time_key in ipairs({ "ctime", "mtime", "atime", "birthtime" }) do
|
|||
meta_fields = fs_stat_meta_fields,
|
||||
|
||||
render = function(entry, conf)
|
||||
local meta = entry[FIELD.meta]
|
||||
local meta = entry[FIELD_META]
|
||||
local stat = meta.stat
|
||||
local fmt = conf and conf.format
|
||||
local ret
|
||||
|
|
@ -253,7 +256,7 @@ M.list = function(url, column_defs, callback)
|
|||
if err then
|
||||
poll(meta_err)
|
||||
else
|
||||
local meta = cache_entry[FIELD.meta]
|
||||
local meta = cache_entry[FIELD_META]
|
||||
-- Make sure we always get fs_stat info for links
|
||||
if entry.type == "link" then
|
||||
read_link_data(fs.join(dir, entry.name), function(link_err, link, link_stat)
|
||||
|
|
@ -262,7 +265,7 @@ M.list = function(url, column_defs, callback)
|
|||
else
|
||||
if not meta then
|
||||
meta = {}
|
||||
cache_entry[FIELD.meta] = meta
|
||||
cache_entry[FIELD_META] = meta
|
||||
end
|
||||
meta.link = link
|
||||
meta.link_stat = link_stat
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
local cache = require("oil.cache")
|
||||
local config = require("oil.config")
|
||||
local constants = require("oil.constants")
|
||||
local fs = require("oil.fs")
|
||||
local files = require("oil.adapters.files")
|
||||
local loading = require("oil.loading")
|
||||
|
|
@ -8,9 +9,10 @@ local sshfs = require("oil.adapters.ssh.sshfs")
|
|||
local pathutil = require("oil.pathutil")
|
||||
local shell = require("oil.shell")
|
||||
local util = require("oil.util")
|
||||
local FIELD = require("oil.constants").FIELD
|
||||
local M = {}
|
||||
|
||||
local FIELD_META = constants.FIELD_META
|
||||
|
||||
---@class oil.sshUrl
|
||||
---@field scheme string
|
||||
---@field host string
|
||||
|
|
@ -96,7 +98,7 @@ end
|
|||
local ssh_columns = {}
|
||||
ssh_columns.permissions = {
|
||||
render = function(entry, conf)
|
||||
local meta = entry[FIELD.meta]
|
||||
local meta = entry[FIELD_META]
|
||||
return permissions.mode_to_str(meta.mode)
|
||||
end,
|
||||
|
||||
|
|
@ -105,7 +107,7 @@ ssh_columns.permissions = {
|
|||
end,
|
||||
|
||||
compare = function(entry, parsed_value)
|
||||
local meta = entry[FIELD.meta]
|
||||
local meta = entry[FIELD_META]
|
||||
if parsed_value and meta.mode then
|
||||
local mask = bit.lshift(1, 12) - 1
|
||||
local old_mode = bit.band(meta.mode, mask)
|
||||
|
|
@ -129,7 +131,7 @@ ssh_columns.permissions = {
|
|||
|
||||
ssh_columns.size = {
|
||||
render = function(entry, conf)
|
||||
local meta = entry[FIELD.meta]
|
||||
local meta = entry[FIELD_META]
|
||||
if not meta.size then
|
||||
return ""
|
||||
elseif meta.size >= 1e9 then
|
||||
|
|
|
|||
|
|
@ -1,10 +1,13 @@
|
|||
local cache = require("oil.cache")
|
||||
local constants = require("oil.constants")
|
||||
local permissions = require("oil.adapters.files.permissions")
|
||||
local SSHConnection = require("oil.adapters.ssh.connection")
|
||||
local util = require("oil.util")
|
||||
local FIELD = require("oil.constants").FIELD
|
||||
local SSHFS = {}
|
||||
|
||||
local FIELD_TYPE = constants.FIELD_TYPE
|
||||
local FIELD_META = constants.FIELD_META
|
||||
|
||||
local typechar_map = {
|
||||
l = "link",
|
||||
d = "directory",
|
||||
|
|
@ -143,7 +146,7 @@ function SSHFS:list_dir(url, path, callback)
|
|||
end
|
||||
local cache_entry = cache.create_entry(url, name, type)
|
||||
entries[name] = cache_entry
|
||||
cache_entry[FIELD.meta] = meta
|
||||
cache_entry[FIELD_META] = meta
|
||||
cache.store_entry(url, cache_entry)
|
||||
end
|
||||
end
|
||||
|
|
@ -161,8 +164,8 @@ function SSHFS:list_dir(url, path, callback)
|
|||
local ok, name, type, meta = pcall(parse_ls_line, line)
|
||||
if ok and name ~= "." and name ~= ".." then
|
||||
local cache_entry = entries[name]
|
||||
if cache_entry[FIELD.type] == "link" then
|
||||
cache_entry[FIELD.meta].link_stat = {
|
||||
if cache_entry[FIELD_TYPE] == "link" then
|
||||
cache_entry[FIELD_META].link_stat = {
|
||||
type = type,
|
||||
size = meta.size,
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue