Skip to content

Commit df0df78

Browse files
committed
(rules) optimize win.subsystem rule by caching frequently called functions
1 parent 0b5e5a6 commit df0df78

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

xmake/rules/windows/xmake.lua

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,10 @@ rule("win.subsystem")
1818

1919
local subsystem = target:data("win.subsystem")
2020
local valid = false
21+
local startswith = string.startswith
22+
local upper = string.upper
2123
for _, s in ipairs(subsystems) do
22-
if string.upper(subsystem):startswith(s) then
24+
if startswith(upper(subsystem), s) then
2325
valid = true
2426
break
2527
end
@@ -28,13 +30,13 @@ rule("win.subsystem")
2830

2931
local linker = target:tool("ld")
3032
linker = path.filename(linker)
31-
if linker:startswith("clang") then
33+
if startswith(linker, "clang") then
3234
target:add("ldflags", "-Wl,-subsystem:" .. subsystem, { force = true })
33-
elseif linker:startswith("link") or linker:startswith("lld-link") then
34-
target:add("ldflags", "/SUBSYSTEM:" .. string.upper(subsystem), { force = true })
35-
elseif linker:startswith("gcc") or linker:startswith("g++") then
35+
elseif startswith(linker, "link") or startswith(linker, "lld-link") then
36+
target:add("ldflags", "/SUBSYSTEM:" .. upper(subsystem), { force = true })
37+
elseif startswith(linker, "gcc") or startswith(linker, "g++") then
3638
target:add("ldflags", "-Wl,-m" .. subsystem, { force = true })
37-
elseif linker:startswith("ld") then
39+
elseif startswith(linker, "ld") then
3840
target:add("ldflags", "-m" .. subsystem, { force = true })
3941
end
4042
end)

0 commit comments

Comments
 (0)