From 4de30256c32cd272482bc6df0c6de78ffc389153 Mon Sep 17 00:00:00 2001 From: Steven Arcangeli Date: Thu, 14 Nov 2024 19:18:20 -0800 Subject: [PATCH] perf: replace vim.endswith and vim.startswith with string.match --- README.md | 3 ++- doc/oil.txt | 3 ++- lua/oil/config.lua | 3 ++- lua/oil/util.lua | 3 ++- 4 files changed, 8 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 8c0bdb3..a3f3013 100644 --- a/README.md +++ b/README.md @@ -214,7 +214,8 @@ require("oil").setup({ show_hidden = false, -- This function defines what is considered a "hidden" file is_hidden_file = function(name, bufnr) - return vim.startswith(name, ".") + local m = name:match("^%.") + return m ~= nil end, -- This function defines what will never be shown, even when `show_hidden` is set is_always_hidden = function(name, bufnr) diff --git a/doc/oil.txt b/doc/oil.txt index b655206..58dee6a 100644 --- a/doc/oil.txt +++ b/doc/oil.txt @@ -99,7 +99,8 @@ CONFIG *oil-confi show_hidden = false, -- This function defines what is considered a "hidden" file is_hidden_file = function(name, bufnr) - return vim.startswith(name, ".") + local m = name:match("^%.") + return m ~= nil end, -- This function defines what will never be shown, even when `show_hidden` is set is_always_hidden = function(name, bufnr) diff --git a/lua/oil/config.lua b/lua/oil/config.lua index 5ced37d..d3eca47 100644 --- a/lua/oil/config.lua +++ b/lua/oil/config.lua @@ -84,7 +84,8 @@ local default_config = { show_hidden = false, -- This function defines what is considered a "hidden" file is_hidden_file = function(name, bufnr) - return vim.startswith(name, ".") + local m = name:match("^%.") + return m ~= nil end, -- This function defines what will never be shown, even when `show_hidden` is set is_always_hidden = function(name, bufnr) diff --git a/lua/oil/util.lua b/lua/oil/util.lua index f5c63e2..947b38a 100644 --- a/lua/oil/util.lua +++ b/lua/oil/util.lua @@ -347,7 +347,8 @@ M.addslash = function(path, os_slash) slash = "\\" end - if not vim.endswith(path, slash) then + local endslash = path:match(slash .. "$") + if not endslash then return path .. slash else return path