Replace 4 comparisons with 1 in privacy math

By replacing a tuple of 4 uint8_t with a single uint32_t, key lookup is
reduced to 1 uint32_t comparison instead of 4 uint8_t comparisons.

Change-Id: I5d85f3009f56306d1773f20bbfa64d23402b8c18
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5348383
Reviewed-by: Charlie Harrison <csharrison@chromium.org>
Commit-Queue: Andrew Paseltiner <apaseltiner@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1269120}
diff --git a/content/browser/attribution_reporting/privacy_math.cc b/content/browser/attribution_reporting/privacy_math.cc
index 3be3f64c4..ff1368d 100644
--- a/content/browser/attribution_reporting/privacy_math.cc
+++ b/content/browser/attribution_reporting/privacy_math.cc
@@ -12,12 +12,12 @@
 #include <iterator>
 #include <map>
 #include <optional>
-#include <tuple>
 #include <utility>
 #include <vector>
 
 #include "base/check_op.h"
 #include "base/notreached.h"
+#include "base/numerics/byte_conversions.h"
 #include "base/numerics/checked_math.h"
 #include "base/rand_util.h"
 #include "base/ranges/algorithm.h"
@@ -81,10 +81,14 @@
   }
 
   // Store these as 8 bit to optimize storage.
-  absl::uint128& cached =
-      map[std::make_tuple(base::checked_cast<uint8_t>(max_reports), it.index(),
-                          base::checked_cast<uint8_t>(window_val),
-                          base::checked_cast<uint8_t>(max_reports_per_type))];
+  const uint8_t key[4] = {
+      base::checked_cast<uint8_t>(max_reports),           //
+      it.index(),                                         //
+      base::checked_cast<uint8_t>(window_val),            //
+      base::checked_cast<uint8_t>(max_reports_per_type),  //
+  };
+
+  absl::uint128& cached = map[base::numerics::U32FromNativeEndian(key)];
   if (cached != 0) {
     return cached;
   }
diff --git a/content/browser/attribution_reporting/privacy_math.h b/content/browser/attribution_reporting/privacy_math.h
index 1456753..cbb9569 100644
--- a/content/browser/attribution_reporting/privacy_math.h
+++ b/content/browser/attribution_reporting/privacy_math.h
@@ -10,7 +10,6 @@
 #include <compare>
 #include <map>
 #include <optional>
-#include <tuple>
 #include <vector>
 
 #include "content/common/content_export.h"
@@ -161,7 +160,7 @@
 //
 // Takes a `StateMap`, to optimize with the cache from previous calls that
 // pre-compute the number of states (`GetNumStatesRecursive()`).
-using ConfigForCache = std::tuple<uint8_t, uint8_t, uint8_t, uint8_t>;
+using ConfigForCache = uint32_t;
 using StateMap = std::map<ConfigForCache, absl::uint128>;
 CONTENT_EXPORT std::vector<FakeEventLevelReport> GetFakeReportsForSequenceIndex(
     const attribution_reporting::TriggerSpecs& specs,