Skip to content

Commit

Permalink
Use absl::flat_hash_map in StatisticsWriter::GenerateStatistics
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 408846483
Change-Id: Ic22876fa24216af32cf62d4ee5037b139527b242
  • Loading branch information
BinExport Authors authored and copybara-github committed Nov 10, 2021
1 parent d13ee1f commit c2d8716
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
8 changes: 4 additions & 4 deletions statistics_writer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
#include "third_party/zynamics/binexport/statistics_writer.h"

#include <iomanip>
#include <map>
#include <string>

#include "third_party/absl/container/flat_hash_map.h"
#include "third_party/zynamics/binexport/call_graph.h"
#include "third_party/zynamics/binexport/flow_graph.h"

Expand All @@ -30,8 +30,8 @@ StatisticsWriter::StatisticsWriter(const std::string& filename)

void StatisticsWriter::GenerateStatistics(
const CallGraph& call_graph, const FlowGraph& flow_graph,
std::map<std::string, size_t>* statistics_ptr) const {
std::map<std::string, size_t>& statistics = *statistics_ptr;
absl::flat_hash_map<std::string, size_t>* statistics_ptr) const {
absl::flat_hash_map<std::string, size_t>& statistics = *statistics_ptr;
statistics.clear();
const Functions& functions = flow_graph.GetFunctions();
statistics["callgraph nodes (functions)"] = functions.size();
Expand Down Expand Up @@ -96,7 +96,7 @@ absl::Status StatisticsWriter::Write(const CallGraph& call_graph,
const Instructions&,
const AddressReferences&,
const AddressSpace&) {
std::map<std::string, size_t> statistics;
absl::flat_hash_map<std::string, size_t> statistics;
GenerateStatistics(call_graph, flow_graph, &statistics);
for (const auto& entry : statistics) {
const std::string padding(32 - entry.first.size(), '.');
Expand Down
7 changes: 4 additions & 3 deletions statistics_writer.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

#include <fstream>

#include "third_party/absl/container/flat_hash_map.h"
#include "third_party/zynamics/binexport/writer.h"

namespace security::binexport {
Expand All @@ -26,9 +27,9 @@ class StatisticsWriter : public Writer {
explicit StatisticsWriter(std::ostream& stream);
explicit StatisticsWriter(const std::string& filename);

void GenerateStatistics(const CallGraph& call_graph,
const FlowGraph& flow_graph,
std::map<std::string, size_t>* statistics) const;
void GenerateStatistics(
const CallGraph& call_graph, const FlowGraph& flow_graph,
absl::flat_hash_map<std::string, size_t>* statistics) const;

absl::Status Write(const CallGraph& call_graph, const FlowGraph& flow_graph,
const Instructions&, const AddressReferences&,
Expand Down

0 comments on commit c2d8716

Please sign in to comment.