aboutsummaryrefslogtreecommitdiffstats
path: root/dir.c
diff options
context:
space:
mode:
author卜部昌平 <shyouhei@ruby-lang.org>2020-06-12 14:08:48 +0900
committer卜部昌平 <shyouhei@ruby-lang.org>2020-06-29 11:05:41 +0900
commit99073f49bf97e1d2f2caab97045de5011edf04b8 (patch)
tree9aeb142052b64587ab0be7320596285f62b868d7 /dir.c
parent70857ae1aa06c85f4c2366aed9a716dfa778ca1b (diff)
downloadruby-99073f49bf97e1d2f2caab97045de5011edf04b8.tar.gz
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.
Diffstat (limited to 'dir.c')
-rw-r--r--dir.c13
1 files changed, 8 insertions, 5 deletions
diff --git a/dir.c b/dir.c
index 42e5304c0f..9c9d40df85 100644
--- a/dir.c
+++ b/dir.c
@@ -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 *