Skip to content

Commit 0284ebc

Browse files
committed
efficiency
1 parent 6f9cf36 commit 0284ebc

File tree

12 files changed

+39
-36
lines changed

12 files changed

+39
-36
lines changed

+stdlib/canonical.m

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,19 +21,21 @@
2121
return
2222
end
2323

24-
if stdlib.isoctave() || isMATLABReleaseOlderThan('R2024a')
25-
c = acanon(p);
26-
else
24+
try
2725
pth = matlab.io.internal.filesystem.resolvePath(p);
2826
c = pth.ResolvedPath;
2927
if strempty(c)
3028
c = stdlib.normalize(p);
3129
end
30+
catch e
31+
if strcmp(e.identifier, 'MATLAB:undefinedVarOrClass') || startsWith(e.message, 'member')
32+
c = acanon(p);
33+
else
34+
rethrow(e)
35+
end
3236
end
3337

34-
try %#ok<*TRYNC>
35-
c = string(c);
36-
end
38+
c = string(c);
3739

3840
end
3941

+stdlib/device.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
if err == 0
1515
i = s.dev;
1616
end
17-
elseif isunix() && stdlib.has_java() && stdlib.java_api() >= 11
17+
elseif isunix() && stdlib.java_api() >= 11
1818
% Java 1.8 is buggy in some corner cases, so we require at least 11.
1919
i = java.nio.file.Files.getAttribute(javaPathObject(path), "unix:dev", javaLinkOption());
2020
end

+stdlib/h5variables.m

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,7 @@
2828
names = {ds.Name};
2929
end
3030

31-
try %#ok<TRYNC>
32-
names = string(names);
33-
end
31+
names = string(names);
3432

3533
end
3634

+stdlib/hard_link_count.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
if err == 0
1818
c = s.nlink;
1919
end
20-
elseif isunix() && stdlib.has_java()
20+
elseif isunix()
2121
c = java.nio.file.Files.getAttribute(javaPathObject(p), "unix:nlink", javaLinkOption());
2222
end
2323

+stdlib/inode.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
if err == 0
1515
i = s.ino;
1616
end
17-
elseif isunix() && stdlib.has_java() && stdlib.java_api() >= 11
17+
elseif isunix() && stdlib.java_api() >= 11
1818
% Java 1.8 is buggy in some corner cases, so we require at least 11.
1919
i = java.nio.file.Files.getAttribute(javaPathObject(path), "unix:ino", javaLinkOption());
2020
end

+stdlib/is_exe.m

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,21 @@
88
end
99
% need to have string array type for p(:)
1010

11-
if ~stdlib.isoctave() && ~isMATLABReleaseOlderThan('R2025a')
11+
try
1212
if isunix
1313
props = ["UserExecute", "GroupExecute", "OtherExecute"];
1414
else
1515
props = "Readable";
1616
end
1717
t = getPermissions(filePermissions(p), props);
1818
ok = isfile(p(:)) & any(t{:,:}, 2);
19-
else
20-
a = file_attributes_legacy(p);
21-
ok = isfile(p) && (a.UserExecute || a.GroupExecute || a.OtherExecute);
19+
catch e
20+
switch e.identifier
21+
case {'MATLAB:UndefinedFunction', 'Octave:undefined-function'}
22+
a = file_attributes_legacy(p);
23+
ok = isfile(p) && (a.UserExecute || a.GroupExecute || a.OtherExecute);
24+
otherwise, rethrow(e)
25+
end
2226
end
2327

2428
end

+stdlib/is_readable.m

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,21 @@
22

33
function ok = is_readable(p)
44

5-
if ~stdlib.isoctave() && ~isMATLABReleaseOlderThan('R2025a')
5+
try
66
props = "Readable";
77
if isunix
88
props = [props, "GroupRead", "OtherRead"];
99
end
1010
t = getPermissions(filePermissions(p), props);
1111
ok = any(t{:,:}, 2);
12-
else
13-
a = file_attributes_legacy(p);
14-
ok = a.UserRead || a.GroupRead || a.OtherRead;
12+
catch e
13+
switch e.identifier
14+
case {'MATLAB:UndefinedFunction', 'Octave:undefined-function'}
15+
a = file_attributes_legacy(p);
16+
ok = a.UserRead || a.GroupRead || a.OtherRead;
17+
otherwise, rethrow(e)
18+
end
1519
end
1620

21+
end
1722
%!assert (is_readable('is_readable.m'))

+stdlib/is_symlink.m

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,6 @@
22
% optional: mex
33

44
function ok = is_symlink(p)
5-
arguments
6-
p {mustBeTextScalar}
7-
end
8-
95

106
try
117
ok = isSymbolicLink(p);

+stdlib/is_url.m

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,6 @@
22
% e.g. https://example.invalid is true
33

44
function y = is_url(s)
5-
arguments
6-
s {mustBeTextScalar}
7-
end
85

96
y = startsWith(s, alphanumericsPattern + "://");
107

+stdlib/is_writable.m

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,20 @@
22

33
function ok = is_writable(p)
44

5-
if ~stdlib.isoctave() && ~isMATLABReleaseOlderThan('R2025a')
5+
try
66
props = "Writable";
77
if isunix
88
props = [props, "GroupWrite", "OtherWrite"];
99
end
1010
t = getPermissions(filePermissions(p), props);
1111
ok = any(t{:,:}, 2);
12-
else
13-
a = file_attributes_legacy(p);
14-
ok = a.UserWrite || a.GroupWrite || a.OtherWrite;
12+
catch e
13+
switch e.identifier
14+
case {'MATLAB:UndefinedFunction', 'Octave:undefined-function'}
15+
a = file_attributes_legacy(p);
16+
ok = a.UserWrite || a.GroupWrite || a.OtherWrite;
17+
otherwise, rethrow(e)
18+
end
1519
end
1620

1721
end

0 commit comments

Comments
 (0)