From 227b633480df2f247e33f3f9a703049b1e6a0c21 Mon Sep 17 00:00:00 2001 From: xiaomx32 <2116906041@qq.com> Date: Wed, 11 Dec 2024 23:01:47 +0800 Subject: [PATCH] optimize 'for' loop: avoid duplicate initialization of variables; delete code format check: currently not very useful --- .github/workflows/code-format-check.yml | 21 ------------------- src/runtime/context.cpp | 27 ++++++++++++++++--------- 2 files changed, 17 insertions(+), 31 deletions(-) delete mode 100644 .github/workflows/code-format-check.yml diff --git a/.github/workflows/code-format-check.yml b/.github/workflows/code-format-check.yml deleted file mode 100644 index 599f73297..000000000 --- a/.github/workflows/code-format-check.yml +++ /dev/null @@ -1,21 +0,0 @@ -name: C++ Code Check -on: [ push, pull_request ] -jobs: - formatting-check: - name: Check C++ Code Formatting - runs-on: ubuntu-24.04 - strategy: - matrix: - path: - - check: 'include' - - check: 'src' - exclude: 'ext' - steps: - - uses: actions/checkout@v4 - - name: Run clang-format style check for C/C++/Protobuf programs. - uses: jidicula/clang-format-action@v4.14.0 - with: - clang-format-version: '18' - check-path: ${{ matrix.path['check'] }} - exclude-regex: ${{ matrix.path['exclude'] }} - fallback-style: 'LLVM' diff --git a/src/runtime/context.cpp b/src/runtime/context.cpp index 15bf93ba2..2c3ac695e 100644 --- a/src/runtime/context.cpp +++ b/src/runtime/context.cpp @@ -117,6 +117,8 @@ class ContextImpl { } explicit ContextImpl(luisa::string_view program_path) noexcept { + using namespace std::string_view_literals; + luisa::filesystem::path program { program_path }; LUISA_INFO( "Created context for program '{}'.", @@ -137,20 +139,25 @@ class ContextImpl { DynamicModule::add_search_path(runtime_directory); } + const auto &extension_so = luisa::filesystem::path(".so"); + const auto &extension_dll = luisa::filesystem::path(".dll"); + const auto &extension_dylib = luisa::filesystem::path(".dylib"); + constexpr std::array possible_prefixes { + "lc-backend-"sv, + "liblc-backend-"sv // Make Mingw happy + }; for (auto &&p : luisa::filesystem::directory_iterator{runtime_directory}) { + auto &&path = p.path(); + auto p_is_regular_file = p.is_regular_file(); + const auto &path_extension = path.extension(); + if ( - auto &&path = p.path(); - p.is_regular_file() && ( - path.extension() == luisa::filesystem::path(".so") || - path.extension() == luisa::filesystem::path(".dll") || - path.extension() == luisa::filesystem::path(".dylib") + p_is_regular_file && ( + path_extension == extension_so || + path_extension == extension_dll || + path_extension == extension_dylib ) ) { - using namespace std::string_view_literals; - constexpr std::array possible_prefixes { - "lc-backend-"sv, - "liblc-backend-"sv // Make Mingw happy - }; auto filename = luisa::to_string(path.stem()); for (auto prefix : possible_prefixes) { if (filename.starts_with(prefix)) {