Repository: carbon-language/carbon-lang
File: common/raw_hashtable_benchmark_helpers.cpp (C++)

Code before:
    ssize_t key_count = (MaxNumKeys / length_buckets.size()) *
                        llvm::count(length_buckets, length);

    raw_keys_buckets[length_index] = &raw_keys_storage.emplace_front(
        MakeRawStrKeys(length, key_count, four_char_strs, random_chars, gen));
  }

  // Now build the actual key array from our intermediate storage by
  // round-robin extracting from the length buckets.
  for (auto [index, key] : llvm::enumerate(keys)) {
    ssize_t bucket = index % length_buckets.size();
    ssize_t length = length_buckets[bucket];
    // We pop a raw key from the list of them associated with this bucket.
    const char* raw_key = raw_keys_buckets[bucket]->pop_back_val();
    // And build our key from that.
    key = llvm::StringRef(raw_key, length);
  }
  // Check that in fact we popped every raw key into our main keys.
  for (const auto& raw_keys : raw_keys_storage) {
    CARBON_CHECK(raw_keys.empty());
  }
  return keys;
}()};

static absl::NoDestructor<llvm::SmallVector<int*>> raw_ptr_keys(llvm::map_range(
    llvm::seq(MaxNumKeys), [](int index) { return new int(index); }));

static absl::NoDestructor<llvm::SmallVector<int>> raw_int_keys(llvm::map_range(
    llvm::seq(MaxNumKeys), [](int index) { return index + 1; }));

template <int LowZeroBits>
static absl::NoDestructor<llvm::SmallVector<LowZeroBitInt<LowZeroBits>>>
    raw_low_zero_bit_int_keys(
        llvm::map_range(llvm::seq(MaxNumKeys), [](int index) {
          return LowZeroBitInt<LowZeroBits>(index + 1);
        }));

namespace {

// Allow generically dispatching over the specific key types we build and
// support.
template <typename T>
auto GetRawKeys() -> llvm::ArrayRef<T> {
  if constexpr (std::is_same_v<T, llvm::StringRef>) {
    return *raw_str_keys;
  } else if constexpr (std::is_pointer_v<T>) {
    return *raw_ptr_keys;
  } else if constexpr (std::is_same_v<T, LowZeroBitInt<12>>) {
    return *raw_low_zero_bit_int_keys<12>;
  } else if constexpr (std::is_same_v<T, LowZeroBitInt<24>>) {
    return *raw_low_zero_bit_int_keys<24>;

Review comment (suggestion):
nit: style guide prefers `{}` for constructing primitive types

```suggestion
    llvm::seq(MaxNumKeys), [](int index) { return new int{index}; }));
```

Code after:
    ssize_t key_count = (MaxNumKeys / length_buckets.size()) *
                        llvm::count(length_buckets, length);

    raw_keys_buckets[length_index] = &raw_keys_storage.emplace_front(
        MakeRawStrKeys(length, key_count, four_char_strs, random_chars, gen));
  }

  // Now build the actual key array from our intermediate storage by
  // round-robin extracting from the length buckets.
  for (auto [index, key] : llvm::enumerate(keys)) {
    ssize_t bucket = index % length_buckets.size();
    ssize_t length = length_buckets[bucket];
    // We pop a raw key from the list of them associated with this bucket.
    const char* raw_key = raw_keys_buckets[bucket]->pop_back_val();
    // And build our key from that.
    key = llvm::StringRef(raw_key, length);
  }
  // Check that in fact we popped every raw key into our main keys.
  for (const auto& raw_keys : raw_keys_storage) {
    CARBON_CHECK(raw_keys.empty());
  }
  return keys;
}()};

static absl::NoDestructor<llvm::SmallVector<int*>> raw_ptr_keys(llvm::map_range(
    llvm::seq(MaxNumKeys), [](int index) { return new int{index}; }));

static absl::NoDestructor<llvm::SmallVector<int>> raw_int_keys(llvm::map_range(
    llvm::seq(MaxNumKeys), [](int index) { return index + 1; }));

template <int LowZeroBits>
static absl::NoDestructor<llvm::SmallVector<LowZeroBitInt<LowZeroBits>>>
    raw_low_zero_bit_int_keys(
        llvm::map_range(llvm::seq(MaxNumKeys), [](int index) {
          return LowZeroBitInt<LowZeroBits>(index + 1);
        }));

namespace {

// Allow generically dispatching over the specific key types we build and
// support.
template <typename T>
auto GetRawKeys() -> llvm::ArrayRef<T> {
  if constexpr (std::is_same_v<T, llvm::StringRef>) {
    return *raw_str_keys;
  } else if constexpr (std::is_pointer_v<T>) {
    return *raw_ptr_keys;
  } else if constexpr (std::is_same_v<T, LowZeroBitInt<12>>) {
    return *raw_low_zero_bit_int_keys<12>;
  } else if constexpr (std::is_same_v<T, LowZeroBitInt<24>>) {
    return *raw_low_zero_bit_int_keys<24>;