mirror of
https://github.com/rui314/mold.git
synced 2024-12-27 10:23:41 +03:00
Use u8[] instead of std::vector to avoid zero-initialization cost
This commit is contained in:
parent
723b0370ef
commit
6fb5754c5b
10
main.cc
10
main.cc
@ -20,11 +20,11 @@ static bool is_text_file(Context<E> &ctx, MemoryMappedFile<E> *mb) {
|
||||
|
||||
template <typename E>
|
||||
std::string_view save_string(Context<E> &ctx, const std::string &str) {
|
||||
std::vector<u8> *buf = new std::vector<u8>(str.size() + 1);
|
||||
memcpy(buf->data(), str.data(), str.size());
|
||||
(*buf)[str.size()] = '\0';
|
||||
ctx.owning_bufs.push_back(std::unique_ptr<std::vector<u8>>(buf));
|
||||
return {(char *)buf->data(), str.size()};
|
||||
u8 *buf = new u8[str.size() + 1];
|
||||
memcpy(buf, str.data(), str.size());
|
||||
buf[str.size()] = '\0';
|
||||
ctx.owning_bufs.push_back(std::unique_ptr<u8[]>(buf));
|
||||
return {(char *)buf, str.size()};
|
||||
}
|
||||
|
||||
std::string get_version_string() {
|
||||
|
2
mold.h
2
mold.h
@ -1434,7 +1434,7 @@ struct Context {
|
||||
|
||||
tbb::concurrent_vector<std::unique_ptr<ObjectFile<E>>> owning_objs;
|
||||
tbb::concurrent_vector<std::unique_ptr<SharedFile<E>>> owning_dsos;
|
||||
tbb::concurrent_vector<std::unique_ptr<std::vector<u8>>> owning_bufs;
|
||||
tbb::concurrent_vector<std::unique_ptr<u8[]>> owning_bufs;
|
||||
tbb::concurrent_vector<std::unique_ptr<ElfShdr<E>>> owning_shdrs;
|
||||
tbb::concurrent_vector<std::unique_ptr<MemoryMappedFile<E>>> owning_mbs;
|
||||
|
||||
|
@ -193,15 +193,15 @@ std::pair<std::string_view, const ElfShdr<E> *>
|
||||
ObjectFile<E>::uncompress_contents(Context<E> &ctx, const ElfShdr<E> &shdr,
|
||||
std::string_view name) {
|
||||
auto do_uncompress = [&](std::string_view data, u64 size) {
|
||||
std::vector<u8> *buf = new std::vector<u8>(size);
|
||||
ctx.owning_bufs.push_back(std::unique_ptr<std::vector<u8>>(buf));
|
||||
u8 *buf = new u8[size];
|
||||
ctx.owning_bufs.push_back(std::unique_ptr<u8[]>(buf));
|
||||
|
||||
unsigned long size2 = size;
|
||||
if (uncompress(buf->data(), &size2, (u8 *)&data[0], data.size()) != Z_OK)
|
||||
if (uncompress(buf, &size2, (u8 *)&data[0], data.size()) != Z_OK)
|
||||
Fatal(ctx) << *this << ": " << name << ": uncompress failed";
|
||||
if (size != size2)
|
||||
Fatal(ctx) << *this << ": " << name << ": uncompress: invalid size";
|
||||
return std::string_view((char *)buf->data(), size);
|
||||
return std::string_view((char *)buf, size);
|
||||
};
|
||||
|
||||
if (name.starts_with(".zdebug")) {
|
||||
|
Loading…
Reference in New Issue
Block a user