From 4c94f90e5d62e012d87a6880b34ddf73b852d3ba Mon Sep 17 00:00:00 2001 From: topjohnwu Date: Tue, 3 Nov 2020 01:16:55 -0800 Subject: [PATCH] Templatize function callbacks --- native/jni/utils/files.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/native/jni/utils/files.cpp b/native/jni/utils/files.cpp index 62ceb607d..105262cc9 100644 --- a/native/jni/utils/files.cpp +++ b/native/jni/utils/files.cpp @@ -45,18 +45,20 @@ int mkdirs(string path, mode_t mode) { return 0; } -static void post_order_walk(int dirfd, const function &&fn) { +template +static void post_order_walk(int dirfd, const Func &fn) { auto dir = xopen_dir(dirfd); if (!dir) return; for (dirent *entry; (entry = xreaddir(dir.get()));) { if (entry->d_type == DT_DIR) - post_order_walk(xopenat(dirfd, entry->d_name, O_RDONLY | O_CLOEXEC), std::move(fn)); + post_order_walk(xopenat(dirfd, entry->d_name, O_RDONLY | O_CLOEXEC), fn); fn(dirfd, entry); } } -static void pre_order_walk(int dirfd, const function &&fn) { +template +static void pre_order_walk(int dirfd, const Func &fn) { auto dir = xopen_dir(dirfd); if (!dir) return; @@ -64,7 +66,7 @@ static void pre_order_walk(int dirfd, const function &&fn) if (!fn(dirfd, entry)) continue; if (entry->d_type == DT_DIR) - pre_order_walk(xopenat(dirfd, entry->d_name, O_RDONLY | O_CLOEXEC), std::move(fn)); + pre_order_walk(xopenat(dirfd, entry->d_name, O_RDONLY | O_CLOEXEC), fn); } }