Skip to content

Commit d58f7b8

Browse files
committed
is_absolute: efficiency
1 parent 69af91c commit d58f7b8

File tree

1 file changed

+3
-8
lines changed

1 file changed

+3
-8
lines changed

+stdlib/is_absolute.m

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
function y = is_absolute(p)
88
arguments
9-
p (1,1) string
9+
p (1,:) char
1010
end
1111

1212
% not Octave is_absolute_filename() because this is a stricter check for "c:" false
@@ -19,14 +19,9 @@
1919
end
2020

2121
if ispc
22-
if ischar(p)
23-
s = p(3); %#ok<UNRCH>
24-
else
25-
s = p{1}(3);
26-
end
27-
y = strlength(stdlib.root_name(p)) && (strcmp(s, '/') || strcmp(s, '\'));
22+
y = strlength(stdlib.root_name(p)) && any(p(3) == ['/', '\']);
2823
else
29-
y = strncmp(p, "/", 1);
24+
y = p(1) == '/';
3025
end
3126

3227
end

0 commit comments

Comments
 (0)