Commit c8718204 authored by ckitagawa's avatar ckitagawa Committed by Commit Bot

[Zucchini-read]: Remove std::set usage to reduce peak memory.

binary tree. std::vector followed by std::sort and std::unique is a
cheaper operation that saves a lot of RAM. Zucchini-read approximately
halves in memory consumption (binary dependent) as a result of this
change.

std: :set is expensive in 64 bit binaries as it uses pointers to store a
Change-Id: Ib7dd8242f8629ba436943695aa8ed3c3b8803ee4
Reviewed-on: https://chromium-review.googlesource.com/951753
Commit-Queue: Calder Kitagawa <ckitagawa@google.com>
Reviewed-by: default avatarSamuel Huang <huangs@chromium.org>
Cr-Commit-Position: refs/heads/master@{#541526}
parent 135f9fbe
......@@ -7,9 +7,9 @@
#include <stddef.h>
#include <stdint.h>
#include <algorithm>
#include <memory>
#include <ostream>
#include <set>
#include <string>
#include "base/bind.h"
......@@ -31,30 +31,22 @@ status::Code ReadReferences(ConstBufferView image,
return status::kStatusInvalidOldImage;
}
auto get_num_locations = [](const ReferenceGroup& group,
Disassembler* disasm) {
size_t count = 0;
auto refs = group.GetReader(disasm);
std::vector<offset_t> targets;
for (const auto& group : disasm->MakeReferenceGroups()) {
targets.clear();
auto refs = group.GetReader(disasm.get());
for (auto ref = refs->GetNext(); ref.has_value(); ref = refs->GetNext())
++count;
return count;
};
targets.push_back(ref->target);
auto get_num_targets = [](const ReferenceGroup& group, Disassembler* disasm) {
std::set<offset_t> target_set;
auto refs = group.GetReader(disasm);
for (auto ref = refs->GetNext(); ref.has_value(); ref = refs->GetNext())
target_set.insert(ref->target);
return target_set.size();
};
size_t num_locations = targets.size();
std::sort(targets.begin(), targets.end());
targets.erase(std::unique(targets.begin(), targets.end()), targets.end());
size_t num_targets = targets.size();
for (const auto& group : disasm->MakeReferenceGroups()) {
out << "Type " << int(group.type_tag().value());
out << ": Pool=" << static_cast<uint32_t>(group.pool_tag().value());
out << ", width=" << group.width();
size_t num_locations = get_num_locations(group, disasm.get());
out << ", #locations=" << num_locations;
size_t num_targets = get_num_targets(group, disasm.get());
out << ", #targets=" << num_targets;
if (num_targets > 0) {
double ratio = static_cast<double>(num_locations) / num_targets;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment