Skip to content

Commit f27214b

Browse files
committed
a little efficient
1 parent 1c4e5f7 commit f27214b

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

src/stdlib_system.F90

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -953,18 +953,19 @@ subroutine make_directory_all(path, err)
953953
character(len=*), intent(in) :: path
954954
type(state_type), optional, intent(out) :: err
955955

956-
integer :: code, i, indx
956+
integer :: i, indx
957957
type(state_type) :: err0
958958
character(len=1) :: sep
959-
logical :: is_dir
959+
logical :: is_dir, check_is_dir
960960

961961
sep = path_sep()
962962
i = 1
963963
indx = find(path, sep, i)
964+
check_is_dir = .true.
964965

965966
do
966967
! Base case to exit the loop
967-
if (indx == 0 .or. indx == len(trim(path))) then
968+
if (indx == 0) then
968969
is_dir = is_directory(path)
969970

970971
if (.not. is_dir) then
@@ -975,12 +976,19 @@ subroutine make_directory_all(path, err)
975976
end if
976977

977978
return
979+
else
980+
exit
978981
end if
979982
end if
980983

981-
is_dir = is_directory(path(1:indx))
984+
if (check_is_dir) then
985+
is_dir = is_directory(path(1:indx))
986+
end if
982987

983988
if (.not. is_dir) then
989+
! no need for further `is_dir` checks
990+
! all paths going forward need to be created
991+
check_is_dir = .false.
984992
call make_directory(path(1:indx), err0)
985993

986994
if (err0%error()) then
@@ -989,7 +997,7 @@ subroutine make_directory_all(path, err)
989997
end if
990998
end if
991999

992-
i = i + 1
1000+
i = i + 1 ! the next occurence of `sep`
9931001
indx = find(path, sep, i)
9941002
end do
9951003
end subroutine make_directory_all

0 commit comments

Comments
 (0)