<commit_before>// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "gpu/command_buffer/service/mailbox_manager.h"

#include <algorithm>

#include "base/rand_util.h"
#include "crypto/hmac.h"
#include "gpu/command_buffer/service/texture_manager.h"

namespace gpu {
namespace gles2 {

MailboxName::MailboxName() {
  std::fill(key, key + sizeof(key), 0);
  std::fill(signature, signature + sizeof(signature), 0);
}

MailboxManager::MailboxManager()
    : hmac_(crypto::HMAC::SHA256),
      mailbox_to_textures_(std::ptr_fun(&MailboxManager::TargetNameLess)) {
  base::RandBytes(private_key_, sizeof(private_key_));
  bool success = hmac_.Init(
      base::StringPiece(private_key_, sizeof(private_key_)));
  DCHECK(success);
  DCHECK(!IsMailboxNameValid(MailboxName()));
}

MailboxManager::~MailboxManager() {
  DCHECK(mailbox_to_textures_.empty());
  DCHECK(textures_to_mailboxes_.empty());
}

void MailboxManager::GenerateMailboxName(MailboxName* name) {
  base::RandBytes(name->key, sizeof(name->key));
  SignMailboxName(name);
}

Texture* MailboxManager::ConsumeTexture(unsigned target,
                                        const MailboxName& name) {
  if (!IsMailboxNameValid(name))
    return NULL;

  MailboxToTextureMap::iterator it =
      mailbox_to_textures_.find(TargetName(target, name));
  if (it == mailbox_to_textures_.end())
    return NULL;

  return it->second->first;
}

bool MailboxManager::ProduceTexture(unsigned target,
                                    const MailboxName& name,
                                    Texture* texture) {
  if (!IsMailboxNameValid(name))
    return false;

  texture->SetMailboxManager(this);<commit_msg>Removing the IsMailboxNameValid check in MailboxManager::ConsumeTexture for perf. According to piman, the check is unnecessary as the mailbox is already in a map.<commit_after>// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "gpu/command_buffer/service/mailbox_manager.h"

#include <algorithm>

#include "base/rand_util.h"
#include "crypto/hmac.h"
#include "gpu/command_buffer/service/texture_manager.h"

namespace gpu {
namespace gles2 {

MailboxName::MailboxName() {
  std::fill(key, key + sizeof(key), 0);
  std::fill(signature, signature + sizeof(signature), 0);
}

MailboxManager::MailboxManager()
    : hmac_(crypto::HMAC::SHA256),
      mailbox_to_textures_(std::ptr_fun(&MailboxManager::TargetNameLess)) {
  base::RandBytes(private_key_, sizeof(private_key_));
  bool success = hmac_.Init(
      base::StringPiece(private_key_, sizeof(private_key_)));
  DCHECK(success);
  DCHECK(!IsMailboxNameValid(MailboxName()));
}

MailboxManager::~MailboxManager() {
  DCHECK(mailbox_to_textures_.empty());
  DCHECK(textures_to_mailboxes_.empty());
}

void MailboxManager::GenerateMailboxName(MailboxName* name) {
  base::RandBytes(name->key, sizeof(name->key));
  SignMailboxName(name);
}

Texture* MailboxManager::ConsumeTexture(unsigned target,
                                        const MailboxName& name) {
  MailboxToTextureMap::iterator it =
      mailbox_to_textures_.find(TargetName(target, name));
  if (it == mailbox_to_textures_.end())
    return NULL;

  DCHECK(IsMailboxNameValid(name));
  return it->second->first;
}

bool MailboxManager::ProduceTexture(unsigned target,
                                    const MailboxName& name,
                                    Texture* texture) {
  if (!IsMailboxNameValid(name))
    return false;

  texture->SetMailboxManager(this);
{'fraction_non_alphanumeric': 0.12142471667566108, 'fraction_numerical': 0.005396654074473826, 'mean_word_length': 4.170153417015341, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5619679', 'n_tokens_mistral': 1154, 'n_tokens_neox': 1133, 'n_words': 232}