Use absl::flat_hash_set inside cpdf_nametree.cpp
Switch from std::set to absl::flat_hash_set inside cpdf_nametree.cpp for
duplicate item tracking.
This speeds up a benchmark that calls FPDF_GetNamedDest() for the 150K+
bookmarks in the ARM Reference Manual by 26%.
Bug: 42270183
Change-Id: I9f35ba2a7daa4f53dd4d4e982b0d3727f8c84203
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/131951
Reviewed-by: Tom Sepez <tsepez@chromium.org>
Commit-Queue: Lei Zhang <thestig@chromium.org>
diff --git a/DEPS b/DEPS
index 2f30e5f..fb1afa2 100644
--- a/DEPS
+++ b/DEPS
@@ -637,6 +637,7 @@
'-third_party/abseil-cpp/absl/base/no_destructor.h',
'-third_party/abseil-cpp/absl/base/nullability.h',
'-third_party/abseil-cpp/absl/container',
+ '+third_party/abseil-cpp/absl/container/flat_hash_set.h',
'+third_party/abseil-cpp/absl/container/inlined_vector.h',
'-third_party/abseil-cpp/absl/crc',
'-third_party/abseil-cpp/absl/flags',
diff --git a/core/fpdfdoc/cpdf_nametree.cpp b/core/fpdfdoc/cpdf_nametree.cpp
index ae6a250..3f81c91 100644
--- a/core/fpdfdoc/cpdf_nametree.cpp
+++ b/core/fpdfdoc/cpdf_nametree.cpp
@@ -19,6 +19,7 @@
#include "core/fxcrt/check.h"
#include "core/fxcrt/ptr_util.h"
#include "core/fxcrt/stl_util.h"
+#include "third_party/abseil-cpp/absl/container/flat_hash_set.h"
namespace {
@@ -191,7 +192,7 @@
}
bool IsTraversedObject(const CPDF_Object* obj,
- std::set<uint32_t>* seen_obj_nums) {
+ absl::flat_hash_set<uint32_t>* seen_obj_nums) {
uint32_t obj_num = obj->GetObjNum();
if (!obj_num) {
return false;
@@ -202,7 +203,7 @@
}
bool IsArrayWithTraversedObject(const CPDF_Array* array,
- std::set<uint32_t>* seen_obj_nums) {
+ absl::flat_hash_set<uint32_t>* seen_obj_nums) {
if (IsTraversedObject(array, seen_obj_nums)) {
return true;
}
@@ -227,7 +228,7 @@
int nLevel,
size_t* nIndex,
NodeToInsert* node_to_insert,
- std::set<uint32_t>* seen_obj_nums) {
+ absl::flat_hash_set<uint32_t>* seen_obj_nums) {
if (nLevel > kNameTreeMaxRecursion) {
return nullptr;
}
@@ -317,7 +318,7 @@
const WideString& csName,
NodeToInsert* node_to_insert) {
size_t nIndex = 0;
- std::set<uint32_t> seen_obj_nums;
+ absl::flat_hash_set<uint32_t> seen_obj_nums;
return SearchNameNodeByNameInternal(pNode, csName, 0, &nIndex, node_to_insert,
&seen_obj_nums);
}
@@ -398,7 +399,7 @@
// Get the total number of key-value pairs in the tree with root |pNode|.
size_t CountNamesInternal(const CPDF_Dictionary* pNode,
int nLevel,
- std::set<const CPDF_Dictionary*>& seen) {
+ absl::flat_hash_set<const CPDF_Dictionary*>& seen) {
if (nLevel > kNameTreeMaxRecursion) {
return 0;
}
@@ -535,7 +536,7 @@
}
size_t CPDF_NameTree::GetCount() const {
- std::set<const CPDF_Dictionary*> seen;
+ absl::flat_hash_set<const CPDF_Dictionary*> seen;
return CountNamesInternal(root_.Get(), 0, seen);
}