1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

glob_opendir: do not goto into a branch

I'm not necessarily against every goto in general, but jumping into a
branch is definitely a bad idea.  Better refactor.
This commit is contained in:
卜部昌平 2020-06-12 14:08:48 +09:00
parent 70857ae1aa
commit 99073f49bf
Notes: git 2020-06-29 11:07:09 +09:00

13
dir.c
View file

@ -2182,6 +2182,7 @@ glob_opendir(ruby_glob_entries_t *ent, DIR *dirp, int flags, rb_encoding *enc)
MEMZERO(ent, ruby_glob_entries_t, 1);
if (flags & FNM_GLOB_NOSORT) {
ent->nosort.dirp = dirp;
return ent;
}
else {
void *newp;
@ -2202,10 +2203,7 @@ glob_opendir(ruby_glob_entries_t *ent, DIR *dirp, int flags, rb_encoding *enc)
while ((dp = READDIR(dirp, enc)) != NULL) {
rb_dirent_t *rdp = dirent_copy(dp, NULL);
if (!rdp) {
nomem:
glob_dir_finish(ent, 0);
closedir(dirp);
return NULL;
goto nomem;
}
if (count >= capacity) {
capacity += 256;
@ -2226,8 +2224,13 @@ glob_opendir(ruby_glob_entries_t *ent, DIR *dirp, int flags, rb_encoding *enc)
}
ruby_qsort(ent->sort.entries, ent->sort.count, sizeof(ent->sort.entries[0]),
glob_sort_cmp, NULL);
return ent;
nomem:
glob_dir_finish(ent, 0);
closedir(dirp);
return NULL;
}
return ent;
}
static rb_dirent_t *