Skip to content

Commit fe9e4ec

Browse files
committed
speed up by removing unneeded checks
1 parent 031fce7 commit fe9e4ec

File tree

4 files changed

+10
-36
lines changed

4 files changed

+10
-36
lines changed

+stdlib/+dotnet/create_symlink.m

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
11
%% DOTNET.CREATE_SYMLINK create symbolic link to target
22

33
function ok = create_symlink(target, link)
4-
arguments
5-
target (1,1) string
6-
link (1,1) string
7-
end
84

95
if ~stdlib.exists(target) || stdlib.strempty(link) || stdlib.exists(link)
106
ok = false;

+stdlib/+dotnet/is_symlink.m

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
%% DOTNET.IS_SYMLINK check if a file is a symbolic link
22

33
function y = is_symlink(file)
4-
arguments
5-
file (1,1) string
6-
end
74

85
if ~stdlib.exists(file)
96
% necessary to avoid having to catch 'MATLAB:NET:CLRException:MethodInvoke' on Windows

+stdlib/+native/samepath.m

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,10 @@
33
% this canonical string method is less preferred to using device + inode.
44

55
function y = samepath(path1, path2)
6-
arguments
7-
path1 string
8-
path2 string
9-
end
10-
11-
assert(isequal(size(path1), size(path2)), "path1 string array size does not match path2 array size")
12-
13-
y = false(size(path1));
146

15-
y(strlength(path1) | strlength(path2)) = true;
16-
17-
% necessary for Matlab < R2024a
18-
if ~any(y)
19-
return
20-
end
7+
c1 = stdlib.canonical(path1, true);
8+
c2 = stdlib.canonical(path2, true);
219

22-
c1 = stdlib.canonical(path1(y), true);
23-
c2 = stdlib.canonical(path2(y), true);
24-
y(y) = strlength(c1) & strcmp(c1, c2);
10+
y = strlength(c1) && strcmp(c1, c2);
2511

2612
end

+stdlib/+python/set_modtime.m

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,17 @@
1-
function ok = set_modtime(file, dt)
2-
arguments
3-
file (1,1) string
4-
dt (1,1) datetime
5-
end
6-
7-
if ~isfile(file)
8-
ok = false;
9-
return
10-
end
1+
function ok = set_modtime(file, time)
112

12-
utc = convertTo(datetime(dt, 'TimeZone', "UTC"), "posixtime");
3+
utc = convertTo(datetime(time, 'TimeZone', "UTC"), "posixtime");
134

145
try
156
s = py.os.stat(file);
167
py.os.utime(file, py.tuple([s.st_atime, utc]));
178
ok = true;
189
catch e
19-
ok = logical.empty;
10+
if e.identifier == "MATLAB:Python:PyException" && contains(e.message, "FileNotFoundError")
11+
ok = false;
12+
else
13+
ok = logical.empty;
14+
end
2015
end
2116

2217
end

0 commit comments

Comments
 (0)