Skip to content

Commit 24ca8a0

Browse files
committed
inode, device: 20x faster
1 parent 419a096 commit 24ca8a0

File tree

5 files changed

+41
-14
lines changed

5 files changed

+41
-14
lines changed

+stdlib/device.m

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,32 @@
22
%
33
%%% Inputs
44
% * file: path to file
5+
% * backend: backend to use
56
%%% Outputs
67
% * i: device index
78
% * b: backend used
89

910
function [i, b] = device(file, backend)
1011
arguments
1112
file string
12-
backend (1,:) string = ["java", "python", "perl", "sys"]
13+
backend (1,:) string = ["java", "python", "sys"]
1314
end
1415

15-
o = stdlib.Backend(mfilename(), backend);
16-
i = o.func(file);
16+
for b = backend
17+
switch b
18+
case "java"
19+
i = stdlib.java.device(file);
20+
case "python"
21+
i = stdlib.python.device(file);
22+
case "sys"
23+
i = stdlib.sys.device(file);
24+
otherwise
25+
error("stdlib:device:ValueError", "Unknown backend: %s", b)
26+
end
27+
28+
if ~isempty(i)
29+
return
30+
end
31+
end
1732

18-
b = o.backend;
1933
end

+stdlib/inode.m

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,32 @@
22
%
33
%%% inputs
44
% * file: path to check
5+
% * backend: backend to use
56
%%% Outputs
67
% * i: inode number
78
% * b: backend used
89

910
function [i, b] = inode(file, backend)
1011
arguments
1112
file string
12-
backend (1,:) string = ["java", "python", "perl", "sys"]
13+
backend (1,:) string = ["java", "python", "sys"]
1314
end
1415

15-
o = stdlib.Backend(mfilename(), backend);
16+
for b = backend
17+
switch b
18+
case "java"
19+
i = stdlib.java.inode(file);
20+
case "python"
21+
i = stdlib.python.inode(file);
22+
case "sys"
23+
i = stdlib.sys.inode(file);
24+
otherwise
25+
error("stdlib:inode:ValueError", "Unknown backend: %s", b)
26+
end
1627

17-
if isscalar(file)
18-
i = o.func(file);
19-
else
20-
i = arrayfun(o.func, file);
28+
if ~isempty(i)
29+
return
30+
end
2131
end
2232

23-
b = o.backend;
24-
2533
end
File renamed without changes.

+stdlib/+perl/inode.m renamed to example/+perl/inode.m

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
%% PERL.INODE
2+
% several times slower than stdlib.sys.inode
3+
14
function [r, cmd] = inode(file)
25

36
r = uint64.empty;

test/TestDisk.m

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,8 +130,9 @@ function test_remove_file(tc)
130130

131131

132132
function test_device(tc, Po, B_device)
133-
i = stdlib.device(Po, B_device);
133+
[i, b] = stdlib.device(Po, B_device);
134134
tc.verifyClass(i, 'uint64')
135+
tc.assertEqual(char(b), B_device)
135136

136137
if ~stdlib.exists(Po)
137138
tc.verifyEmpty(i)
@@ -144,8 +145,9 @@ function test_device(tc, Po, B_device)
144145

145146
function test_inode(tc, Po, B_device)
146147

147-
i = stdlib.inode(Po, B_device);
148+
[i, b] = stdlib.inode(Po, B_device);
148149
tc.verifyClass(i, 'uint64')
150+
tc.assertEqual(char(b), B_device)
149151

150152
if ~stdlib.exists(Po)
151153
tc.verifyEmpty(i)

0 commit comments

Comments
 (0)