Skip to content

Commit ab27ae0

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

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

src/stdlib_system.F90

Lines changed: 13 additions & 7 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
@@ -973,14 +974,19 @@ subroutine make_directory_all(path, err)
973974
if (err0%error()) then
974975
call err0%handle(err)
975976
end if
976-
977-
return
978977
end if
978+
979+
return
979980
end if
980981

981-
is_dir = is_directory(path(1:indx))
982+
if (check_is_dir) then
983+
is_dir = is_directory(path(1:indx))
984+
end if
982985

983986
if (.not. is_dir) then
987+
! no need for further `is_dir` checks
988+
! all paths going forward need to be created
989+
check_is_dir = .false.
984990
call make_directory(path(1:indx), err0)
985991

986992
if (err0%error()) then
@@ -989,7 +995,7 @@ subroutine make_directory_all(path, err)
989995
end if
990996
end if
991997

992-
i = i + 1
998+
i = i + 1 ! the next occurence of `sep`
993999
indx = find(path, sep, i)
9941000
end do
9951001
end subroutine make_directory_all

0 commit comments

Comments
 (0)