Skip to content

Commit 6a190be

Browse files
committed
better efficiency
1 parent 30a7b85 commit 6a190be

File tree

4 files changed

+9
-11
lines changed

4 files changed

+9
-11
lines changed

+stdlib/+java/is_admin.m

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@
44
% Administrator group SID (S-1-5-32-544) is not an appropriate check .getGroupIDs because it
55
% only tells if a user is *allowed* to run as admin, not if they are currently running as admin.
66

7-
ok = logical.empty;
87

9-
try %#ok<TRYNC>
8+
try
109
ok = com.sun.security.auth.module.UnixSystem().getUid() == 0;
10+
catch
11+
ok = logical.empty;
1112
end
1213

1314
end

+stdlib/+sys/is_admin.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
function y = is_admin()
1+
function [y, cmd] = is_admin()
22

33
if ispc()
44
cmd = 'pwsh -c "([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)"';
@@ -9,7 +9,7 @@
99
[s, r] = system(cmd);
1010
if s ~= 0
1111
warning("stdlib:is_admin:RuntimeError", "Failed to execute command '%s': %s", cmd, r);
12-
y = false;
12+
y = logical.empty;
1313
return
1414
end
1515

+stdlib/strempty.m

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,6 @@
22

33
function y = strempty(s)
44

5-
if isempty(s)
6-
y = true;
7-
else
8-
y = strlength(s) == 0;
9-
end
10-
5+
y = isempty(s) | strlength(s) == 0;
116

127
end

test/TestSys.m

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,9 @@ function test_all_toolboxes(tc)
5252
end
5353

5454
function test_platform_tell(tc)
55-
tc.verifyClass(stdlib.platform_tell(), 'char')
55+
r = stdlib.platform_tell();
56+
tc.verifyClass(r, 'char')
57+
tc.verifyNotEmpty(r)
5658
end
5759

5860

0 commit comments

Comments
 (0)