From 48077dd91a36b3eebf3c13adbc501c9cf4ad3bd6 Mon Sep 17 00:00:00 2001 From: Rui Ueyama Date: Sat, 11 Jan 2025 21:26:40 +0900 Subject: [PATCH] Refactor --- src/output-chunks.cc | 8 +++----- src/passes.cc | 20 +++++++++++--------- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/output-chunks.cc b/src/output-chunks.cc index 9902c8b2bf..dad8994b8a 100644 --- a/src/output-chunks.cc +++ b/src/output-chunks.cc @@ -2661,10 +2661,8 @@ void VerdefSection::construct(Context &ctx) { }; std::string_view soname = ctx.arg.soname; - if (soname.empty()) { - std::filesystem::path path(ctx.arg.output); - soname = save_string(ctx, path.filename().string()); - } + if (soname.empty()) + soname = save_string(ctx, path_filename(ctx.arg.output)); write(soname, 1, VER_FLG_BASE); i64 idx = VER_NDX_LAST_RESERVED + 1; @@ -2965,7 +2963,7 @@ void ComdatGroupSection::copy_buf(Context &ctx) { template void GnuDebuglinkSection::update_shdr(Context &ctx) { - filename = std::filesystem::path(ctx.arg.separate_debug_file).filename().string(); + filename = path_filename(ctx.arg.separate_debug_file); this->shdr.sh_size = align_to(filename.size() + 1, 4) + 4; } diff --git a/src/passes.cc b/src/passes.cc index 99183be3cc..cfed2647b6 100644 --- a/src/passes.cc +++ b/src/passes.cc @@ -66,10 +66,11 @@ void apply_exclude_libs(Context &ctx) { std::unordered_set set(ctx.arg.exclude_libs.begin(), ctx.arg.exclude_libs.end()); - for (ObjectFile *file : ctx.objs) - if (!file->archive_name.empty()) - if (set.contains(path_filename(file->archive_name)) || set.contains("ALL")) - file->exclude_libs = true; + if (!set.empty()) + for (ObjectFile *file : ctx.objs) + if (!file->archive_name.empty()) + if (set.contains(path_filename(file->archive_name)) || set.contains("ALL")) + file->exclude_libs = true; } template @@ -863,11 +864,12 @@ void add_synthetic_symbols(Context &ctx) { template void apply_section_align(Context &ctx) { - for (Chunk *chunk : ctx.chunks) - if (OutputSection *osec = chunk->to_osec()) - if (auto it = ctx.arg.section_align.find(osec->name); - it != ctx.arg.section_align.end()) - osec->shdr.sh_addralign = it->second; + std::unordered_map &map = ctx.arg.section_align; + if (!map.empty()) + for (Chunk *chunk : ctx.chunks) + if (OutputSection *osec = chunk->to_osec()) + if (auto it = map.find(osec->name); it != map.end()) + osec->shdr.sh_addralign = it->second; } template