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,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],
})