Skip to content

Commit 9f10a1d

Browse files
committed
posix: don't coerce to string for efficiency
1 parent c2f825a commit 9f10a1d

File tree

9 files changed

+13
-16
lines changed

9 files changed

+13
-16
lines changed

+stdlib/expanduser.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
return
2020
end
2121

22-
home = stdlib.homedir();
22+
home = string(stdlib.homedir());
2323
if ~strlength(home), return, end
2424

2525
if L < 2

+stdlib/handle2filename.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
fileHandle (1,1) {mustBeInteger}
77
end
88

9-
n = "";
9+
n = '';
1010

1111
if fileHandle >= 0
1212
n = stdlib.posix(fopen(fileHandle));

+stdlib/posix.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
function r = posix(p)
77
arguments
8-
p (1,1) string
8+
p {mustBeTextScalar}
99
end
1010

1111
if ispc

+stdlib/windows_shortname.m

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929

3030
s = string(s);
3131

32-
3332
end
3433

3534
%!testif 0

test/TestCanonical.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
methods(Test)
1919

2020
function test_canonical(tc, p)
21-
tc.verifyEqual(stdlib.canonical(p{1}, true), p{2})
21+
tc.verifyEqual(stdlib.canonical(p{1}, true), string(p{2}))
2222
end
2323

2424
end

test/TestFileImpure.m

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
{"..", "./..", true}, ...
1313
{"..", pwd() + "/..", true}}
1414

15-
ph = {{0, '"stdin"'}, {1, '"stdout"'}, {2, '"stderr"'}, {fopen(tempname()), ""}}
15+
ph = {{0, '"stdin"'}, {1, '"stdout"'}, {2, '"stderr"'}, {fopen(tempname()), ''}}
1616

1717
p_file_size = {mfilename("fullpath") + ".m", "", pwd()}
1818
end
@@ -37,7 +37,7 @@ function test_is_writable(tc, p_is_writable)
3737

3838

3939
function test_expanduser(tc, p_expand)
40-
tc.verifyEqual(stdlib.expanduser(p_expand{1}), p_expand{2})
40+
tc.verifyEqual(stdlib.expanduser(p_expand{1}), string(p_expand{2}))
4141
end
4242

4343

@@ -70,7 +70,7 @@ function test_get_pid(tc)
7070

7171

7272
function test_handle2filename(tc, ph)
73-
tc.verifyEqual(stdlib.handle2filename(ph{1}), string(ph{2}))
73+
tc.verifyEqual(stdlib.handle2filename(ph{1}), ph{2})
7474
end
7575

7676
end

test/TestJoin.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
methods (Test)
2121
function test_join(tc, p)
22-
tc.verifyEqual(stdlib.join(p{1}, p{2}), p{3})
22+
tc.verifyEqual(stdlib.join(p{1}, p{2}), string(p{3}))
2323
end
2424
end
2525

test/TestResolve.m

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,9 @@ function test_resolve_relative(tc)
1111
import matlab.unittest.constraints.StartsWithSubstring
1212
import matlab.unittest.constraints.ContainsSubstring
1313

14-
td = stdlib.posix(pwd());
15-
1614
% all non-existing files
1715

18-
tc.verifyEqual(stdlib.resolve("", true), stdlib.posix(td))
16+
tc.verifyEqual(stdlib.resolve("", true), string(stdlib.posix(pwd())))
1917

2018
pabs = stdlib.resolve('2foo', true);
2119
pabs2 = stdlib.resolve('4foo', true);
@@ -41,7 +39,7 @@ function test_resolve_relative(tc)
4139
end
4240

4341
function test_resolve_fullpath(tc, p)
44-
tc.verifyEqual(stdlib.resolve(p{1}, true), p{2})
42+
tc.verifyEqual(stdlib.resolve(p{1}, true), string(p{2}))
4543
end
4644

4745
end

test/TestWindowsCOM.m

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
properties (TestParameter)
44
Pn = {""}
5-
Pmr = {string(matlabroot), stdlib.posix(matlabroot)}
5+
Pmr = {matlabroot, stdlib.posix(matlabroot)}
66
end
77

88
methods (Test)
@@ -38,9 +38,9 @@ function test_short_file(tc, Pmr)
3838
if contains(Pmr, " ")
3939
tc.verifySubstring(s, "~")
4040
end
41-
tc.verifyEqual(stdlib.canonical(s), stdlib.posix(Pmr), "shortname didn't resolve same as canonical")
41+
tc.verifyEqual(stdlib.canonical(s), string(stdlib.posix(Pmr)), "shortname didn't resolve same as canonical")
4242
else
43-
tc.verifyEqual(s, Pmr)
43+
tc.verifyEqual(string(s), string(Pmr))
4444
end
4545

4646
end

0 commit comments

Comments
 (0)