Skip to content

Commit e0006fe

Browse files
committed
performance, compatibility
1 parent e0af872 commit e0006fe

File tree

2 files changed

+23
-14
lines changed

2 files changed

+23
-14
lines changed

+stdlib/matlabOlderThan.m

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,26 @@
11
%% MATLABOLDERTHAN compare Matlab release name only e.g. R2025a
2-
% this is to allow a basic version check back to R2016b at least
2+
% this is to allow a basic version check back to very old Matlab
33

44
function isOlder = matlabOlderThan(release)
55

66
try
77
isOlder = isMATLABReleaseOlderThan(release);
88
catch e
9-
if e.identifier ~= "MATLAB:UndefinedFunction"
9+
if ~strcmp(e.identifier, 'MATLAB:UndefinedFunction')
1010
rethrow(e)
1111
end
1212

13-
release = string(release);
14-
assert(isscalar(release) && strlength(release) == 6 && startsWith(release, "R"), "Release must be a string like 'R2025a'")
13+
r = char(release);
14+
assert(length(r) == 6 && r(1) == 'R', "Release must be a string like 'R2025a'")
1515

1616
curr = version('-release');
17-
release = extractAfter(release, 1);
18-
isOlder = curr < release;
17+
nc = str2double(curr(1:4));
18+
nv = str2double(r(2:5));
19+
if nc == nv
20+
isOlder = curr(5) < r(6);
21+
else
22+
isOlder = nc < nv;
23+
end
1924
end
2025

2126
end

+stdlib/platform_tell.m

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
try
77
r = matlabRelease().Release;
88
catch
9-
r = "R" + version('-release');
9+
r = ['R' version('-release')];
1010
end
1111

1212
raw = struct('matlab_release', r, ...
@@ -26,20 +26,22 @@
2626

2727
pv = stdlib.python_version();
2828
if ~isempty(pv)
29-
raw.python_version = sprintf("%d.%d.%d",pv(1), pv(2), pv(3));
29+
raw.python_version = sprintf('%d.%d.%d', pv(1), pv(2), pv(3));
3030
raw.python_home = stdlib.python_home();
3131
end
3232

3333
if ismac()
3434
raw.xcode_version = stdlib.xcode_version();
3535
end
3636

37-
for lang = ["C", "Cpp", "Fortran"]
37+
langs = {'C', 'Cpp', 'Fortran'};
38+
for i = 1:length(langs)
39+
lang = langs{i};
3840
co = mex.getCompilerConfigurations(lang);
39-
ct = ['compiler_' lang{1}];
40-
vt = ['compiler_' lang{1} '_version'];
41-
raw.(ct) = "";
42-
raw.(vt) = "";
41+
ct = ['compiler_' lang];
42+
vt = ['compiler_' lang '_version'];
43+
raw.(ct) = '';
44+
raw.(vt) = '';
4345

4446
if ~isempty(co)
4547
raw.(ct) = co.ShortName;
@@ -48,11 +50,13 @@
4850
end
4951

5052
try
51-
json = jsonencode(raw, "PrettyPrint", true);
53+
json = jsonencode(raw, 'PrettyPrint', true);
5254
catch e
5355
switch e.identifier
5456
case {'MATLAB:json:UnmatchedParameter', 'MATLAB:maxrhs'}
5557
json = jsonencode(raw);
58+
case 'MATLAB:UndefinedFunction'
59+
json = raw;
5660
otherwise
5761
rethrow(e)
5862
end

0 commit comments

Comments
 (0)