refactor: small perf win by eliminating string object keys

This commit is contained in:
Steven Arcangeli 2023-06-25 10:14:28 -07:00
parent db60c32d93
commit 4a4e0f4013
12 changed files with 151 additions and 111 deletions

View file

@ -1,6 +1,7 @@
local cache = require("oil.cache")
local columns = require("oil.columns")
local config = require("oil.config")
local constants = require("oil.constants")
local oil = require("oil")
local parser = require("oil.mutator.parser")
local pathutil = require("oil.pathutil")
@ -9,9 +10,11 @@ local Progress = require("oil.mutator.progress")
local Trie = require("oil.mutator.trie")
local util = require("oil.util")
local view = require("oil.view")
local FIELD = require("oil.constants").FIELD
local M = {}
local FIELD_NAME = constants.FIELD_NAME
local FIELD_TYPE = constants.FIELD_TYPE
---@alias oil.Action oil.CreateAction|oil.DeleteAction|oil.MoveAction|oil.CopyAction|oil.ChangeAction
---@class oil.CreateAction
@ -129,17 +132,17 @@ M.create_actions_from_diffs = function(all_diffs)
for i, diff in ipairs(diffs) do
table.insert(actions, {
type = i == #diffs and "move" or "copy",
entry_type = entry[FIELD.type],
entry_type = entry[FIELD_TYPE],
dest_url = diff.dest,
src_url = cache.get_parent_url(id) .. entry[FIELD.name],
src_url = cache.get_parent_url(id) .. entry[FIELD_NAME],
})
end
else
-- DELETE when no create
table.insert(actions, {
type = "delete",
entry_type = entry[FIELD.type],
url = cache.get_parent_url(id) .. entry[FIELD.name],
entry_type = entry[FIELD_TYPE],
url = cache.get_parent_url(id) .. entry[FIELD_NAME],
})
end
else
@ -147,8 +150,8 @@ M.create_actions_from_diffs = function(all_diffs)
for _, diff in ipairs(diffs) do
table.insert(actions, {
type = "copy",
entry_type = entry[FIELD.type],
src_url = cache.get_parent_url(id) .. entry[FIELD.name],
entry_type = entry[FIELD_TYPE],
src_url = cache.get_parent_url(id) .. entry[FIELD_NAME],
dest_url = diff.dest,
})
end

View file

@ -1,11 +1,16 @@
local cache = require("oil.cache")
local columns = require("oil.columns")
local constants = require("oil.constants")
local fs = require("oil.fs")
local util = require("oil.util")
local view = require("oil.view")
local FIELD = require("oil.constants").FIELD
local M = {}
local FIELD_ID = constants.FIELD_ID
local FIELD_NAME = constants.FIELD_NAME
local FIELD_TYPE = constants.FIELD_TYPE
local FIELD_META = constants.FIELD_META
---@alias oil.Diff oil.DiffNew|oil.DiffDelete|oil.DiffChange
---@class oil.DiffNew
@ -102,8 +107,8 @@ M.parse_line = function(adapter, line, column_defs)
end
-- Parse the symlink syntax
local meta = entry[FIELD.meta]
local entry_type = entry[FIELD.type]
local meta = entry[FIELD_META]
local entry_type = entry[FIELD_TYPE]
if entry_type == "link" and meta and meta.link then
local name_pieces = vim.split(ret.name, " -> ", { plain = true })
if #name_pieces ~= 2 then
@ -118,7 +123,7 @@ M.parse_line = function(adapter, line, column_defs)
-- Try to keep the same file type
if entry_type ~= "directory" and entry_type ~= "file" and ret._type ~= "directory" then
ret._type = entry[FIELD.type]
ret._type = entry[FIELD_TYPE]
end
return { data = ret, entry = entry, ranges = ranges }
@ -148,7 +153,7 @@ M.parse = function(bufnr)
local original_entries = {}
for _, child in pairs(children) do
if view.should_display(child, bufnr) then
original_entries[child[FIELD.name]] = child[FIELD.id]
original_entries[child[FIELD_NAME]] = child[FIELD_ID]
end
end
local seen_names = {}
@ -193,9 +198,9 @@ M.parse = function(bufnr)
goto continue
end
check_dupe(parsed_entry.name, i)
local meta = entry[FIELD.meta]
local meta = entry[FIELD_META]
if original_entries[parsed_entry.name] == parsed_entry.id then
if entry[FIELD.type] == "link" and not compare_link_target(meta, parsed_entry) then
if entry[FIELD_TYPE] == "link" and not compare_link_target(meta, parsed_entry) then
table.insert(diffs, {
type = "new",
name = parsed_entry.name,
@ -221,7 +226,7 @@ M.parse = function(bufnr)
table.insert(diffs, {
type = "change",
name = parsed_entry.name,
entry_type = entry[FIELD.type],
entry_type = entry[FIELD_TYPE],
column = col_name,
value = parsed_entry[col_name],
})