diff options
author | Anton Yuzhaninov <citrin+git@citrin.ru> | 2022-02-26 13:56:36 +0000 |
---|---|---|
committer | Anton Yuzhaninov <citrin+git@citrin.ru> | 2022-02-26 13:56:36 +0000 |
commit | 431b3b892f0dd29581406dcc4ed690358d5780ca (patch) | |
tree | 58997fbb1db98a33f6eea12ba550ec5789ea3616 /lualib/lua_util.lua | |
parent | ba7f6982b0b582b56e48da778784315b5d63d2be (diff) | |
download | rspamd-431b3b892f0dd29581406dcc4ed690358d5780ca.tar.gz rspamd-431b3b892f0dd29581406dcc4ed690358d5780ca.zip |
[Minor] Microoptimize lua_util.str_endswith
Use find to check string suffix instead of sub (which involves string
interning of a returned string). Benchmarks with LuaJIT 2.1.0 shows
that an option with find is significantly faster.
While here added unit test for this function.
Diffstat (limited to 'lualib/lua_util.lua')
-rw-r--r-- | lualib/lua_util.lua | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/lualib/lua_util.lua b/lualib/lua_util.lua index 308663399..7cabeed2d 100644 --- a/lualib/lua_util.lua +++ b/lualib/lua_util.lua @@ -113,7 +113,7 @@ end -- @return {boolean} true if text ends with the specified suffix, false otherwise --]] exports.str_endswith = function(s, suffix) - return s:sub(-suffix:len()) == suffix + return s:find(suffix, -suffix:len(), true) ~= nil end --[[[ |