1
1
mirror of https://github.com/rui314/mold.git synced 2024-10-04 16:48:04 +03:00

Use std::erase_if instead of our own

I didn't know that C++20 has this function.
This commit is contained in:
Rui Ueyama 2022-01-21 10:39:46 +09:00
parent be6ae07ac1
commit 2b034335ec
8 changed files with 22 additions and 25 deletions

View File

@ -466,7 +466,7 @@ static int elf_main(int argc, char **argv) {
// Uniquify shared object files by soname
{
std::unordered_set<std::string_view> seen;
erase(ctx.dsos, [&](SharedFile<E> *file) {
std::erase_if(ctx.dsos, [&](SharedFile<E> *file) {
return !seen.insert(file->soname).second;
});
}
@ -630,7 +630,7 @@ static int elf_main(int argc, char **argv) {
// section to the special EHFrameSection.
{
Timer t(ctx, "eh_frame");
erase(ctx.chunks, [](Chunk<E> *chunk) {
std::erase_if(ctx.chunks, [](Chunk<E> *chunk) {
return chunk->kind == Chunk<E>::REGULAR &&
chunk->name == ".eh_frame";
});
@ -641,7 +641,7 @@ static int elf_main(int argc, char **argv) {
for (Chunk<E> *chunk : ctx.chunks)
chunk->update_shdr(ctx);
erase(ctx.chunks, [](Chunk<E> *chunk) {
std::erase_if(ctx.chunks, [](Chunk<E> *chunk) {
return chunk->kind == Chunk<E>::SYNTHETIC &&
chunk->shdr.sh_size == 0;
});

View File

@ -198,7 +198,7 @@ std::vector<ElfPhdr<E>> create_phdr(Context<E> &ctx) {
// Create PT_LOAD segments.
{
std::vector<Chunk<E> *> chunks = ctx.chunks;
erase(chunks, is_tbss);
std::erase_if(chunks, is_tbss);
for (i64 i = 0, end = chunks.size(); i < end;) {
Chunk<E> *first = chunks[i++];
@ -1443,7 +1443,7 @@ void EhFrameSection<E>::construct(Context<E> &ctx) {
// Remove dead FDEs and assign them offsets within their corresponding
// CIE group.
tbb::parallel_for_each(ctx.objs, [&](ObjectFile<E> *file) {
erase(file->fdes, [](FdeRecord<E> &fde) { return !fde.is_alive; });
std::erase_if(file->fdes, [](FdeRecord<E> &fde) { return !fde.is_alive; });
i64 offset = 0;
for (FdeRecord<E> &fde : file->fdes) {
@ -1630,7 +1630,7 @@ void VerneedSection<E>::construct(Context<E> &ctx) {
std::vector<Symbol<E> *> syms(ctx.dynsym->symbols.begin() + 1,
ctx.dynsym->symbols.end());
erase(syms, [](Symbol<E> *sym) {
std::erase_if(syms, [](Symbol<E> *sym) {
return !sym->file->is_dso || sym->ver_idx <= VER_NDX_LAST_RESERVED;
});

View File

@ -94,7 +94,7 @@ void resolve_symbols(Context<E> &ctx) {
// Mark reachable objects to decide which files to include
// into an output.
std::vector<InputFile<E> *> live_set = files;
erase(live_set, [](InputFile<E> *file) { return !file->is_alive; });
std::erase_if(live_set, [](InputFile<E> *file) { return !file->is_alive; });
auto mark_symbol = [&](std::string_view name) {
if (InputFile<E> *file = get_symbol(ctx, name)->file)
@ -127,8 +127,8 @@ void resolve_symbols(Context<E> &ctx) {
});
// Remove unused files
erase(ctx.objs, [](InputFile<E> *file) { return !file->is_alive; });
erase(ctx.dsos, [](InputFile<E> *file) { return !file->is_alive; });
std::erase_if(ctx.objs, [](InputFile<E> *file) { return !file->is_alive; });
std::erase_if(ctx.dsos, [](InputFile<E> *file) { return !file->is_alive; });
}
template <typename E>
@ -807,7 +807,10 @@ void clear_padding(Context<E> &ctx) {
};
std::vector<Chunk<E> *> chunks = ctx.chunks;
erase(chunks, [](Chunk<E> *chunk) { return chunk->shdr.sh_type == SHT_NOBITS; });
std::erase_if(chunks, [](Chunk<E> *chunk) {
return chunk->shdr.sh_type == SHT_NOBITS;
});
for (i64 i = 1; i < chunks.size(); i++)
zero(chunks[i - 1], chunks[i]->shdr.sh_offset);

View File

@ -511,11 +511,9 @@ void combine_objects(Context<E> &ctx, std::span<std::string_view> file_args) {
break;
}
files.erase(std::remove_if(files.begin(), files.end(),
[](std::unique_ptr<RObjectFile<E>> &file) {
return !file->is_alive;
}),
files.end());
std::erase_if(files, [](std::unique_ptr<RObjectFile<E>> &file) {
return !file->is_alive;
});
// Remove duplicate comdat groups
std::unordered_set<std::string_view> comdat_groups;

View File

@ -84,7 +84,8 @@ static void mark(Context<E> &ctx, const std::vector<Subsection<E> *> &rootset) {
template <typename E>
static void sweep(Context<E> &ctx) {
for (ObjectFile<E> *file : ctx.objs) {
erase(file->subsections, [](const std::unique_ptr<Subsection<E>> &subsec) {
std::erase_if(file->subsections,
[](const std::unique_ptr<Subsection<E>> &subsec) {
return !subsec->is_alive;
});
}

View File

@ -421,8 +421,8 @@ static int do_main(int argc, char **argv) {
create_internal_file(ctx);
erase(ctx.objs, [](ObjectFile<E> *file) { return !file->is_alive; });
erase(ctx.dylibs, [](DylibFile<E> *file) { return !file->is_alive; });
std::erase_if(ctx.objs, [](ObjectFile<E> *file) { return !file->is_alive; });
std::erase_if(ctx.dylibs, [](DylibFile<E> *file) { return !file->is_alive; });
if (ctx.arg.trace) {
for (ObjectFile<E> *file : ctx.objs)
@ -452,7 +452,7 @@ static int do_main(int argc, char **argv) {
scan_unwind_info(ctx);
if (ctx.arg.dead_strip_dylibs)
erase(ctx.dylibs, [](DylibFile<E> *file) { return !file->is_needed; });
std::erase_if(ctx.dylibs, [](DylibFile<E> *file) { return !file->is_needed; });
export_symbols(ctx);
i64 output_size = assign_offsets(ctx);

View File

@ -129,7 +129,7 @@ static std::vector<SplitInfo<E>> split(Context<E> &ctx, ObjectFile<E> &file) {
}
}
erase(vec, [](const SplitInfo<E> &info) { return !info.isec; });
std::erase_if(vec, [](const SplitInfo<E> &info) { return !info.isec; });
sort(vec, [](const SplitInfo<E> &a, const SplitInfo<E> &b) {
return a.isec->hdr.addr < b.isec->hdr.addr;

5
mold.h
View File

@ -205,11 +205,6 @@ inline std::vector<T> flatten(std::vector<std::vector<T>> &vec) {
return ret;
}
template <typename T, typename U>
inline void erase(std::vector<T> &vec, U pred) {
vec.erase(std::remove_if(vec.begin(), vec.end(), pred), vec.end());
}
template <typename T>
inline void sort(T &vec) {
std::stable_sort(vec.begin(), vec.end());