<commit_before>#include "taichi/backends/dx/dx_info_queue.h"

namespace taichi {
namespace lang {
namespace directx11 {

void check_dx_error(HRESULT hr, const char *msg);

namespace {
inline std::string trim_string(const std::string &s) {
  int begin = 0, end = (int)s.size();
  while (begin < end && std::isspace(s[begin])) {
    begin++;
  }
  while (begin < end && std::isspace(s[end - 1])) {
    end--;
  }
  return std::string(s.begin() + begin, s.begin() + end);
}
}  // namespace

std::string munch_token(std::string &s) {
  if (s.empty()) {
    return "";
  }
  size_t idx = s.find(' ');
  std::string ret;
  ret = trim_string(s.substr(0, idx));
  s = s.substr(idx + 1);
  if (ret.empty() == false && ret.back() == ',')
    ret.pop_back();
  return ret;
}

std::vector<Dx11InfoQueue::Entry> Dx11InfoQueue::parse_reference_count(
    const std::vector<std::string> messages) {
  std::vector<Dx11InfoQueue::Entry> ret;
  for (std::string line : messages) {
    Dx11InfoQueue::Entry entry;
    line = trim_string(line);
    std::string x;
    x = munch_token(line);

    // Example 1: "Live ID3D11Query at 0x0000018F64E81DA0, Refcount: 0, IntRef:
    // 1" Example 2: "Live ID3D11Buffer at 0x000001F8AF284370, Name: buffer
    // alloc#0 size=1048576, Refcount: 1, IntRef: 1"

    if (x != "Live")
      continue;

    x = munch_token(line);
    entry.type = x;

    x = munch_token(line);
    if (x != "at")<commit_msg>[dx11] Fix parse_reference_count signature (#4189)<commit_after>#include "taichi/backends/dx/dx_info_queue.h"

namespace taichi {
namespace lang {
namespace directx11 {

void check_dx_error(HRESULT hr, const char *msg);

namespace {
inline std::string trim_string(const std::string &s) {
  int begin = 0, end = (int)s.size();
  while (begin < end && std::isspace(s[begin])) {
    begin++;
  }
  while (begin < end && std::isspace(s[end - 1])) {
    end--;
  }
  return std::string(s.begin() + begin, s.begin() + end);
}
}  // namespace

std::string munch_token(std::string &s) {
  if (s.empty()) {
    return "";
  }
  size_t idx = s.find(' ');
  std::string ret;
  ret = trim_string(s.substr(0, idx));
  s = s.substr(idx + 1);
  if (ret.empty() == false && ret.back() == ',')
    ret.pop_back();
  return ret;
}

std::vector<Dx11InfoQueue::Entry> Dx11InfoQueue::parse_reference_count(
    const std::vector<std::string> &messages) {
  std::vector<Dx11InfoQueue::Entry> ret;
  for (std::string line : messages) {
    Dx11InfoQueue::Entry entry;
    line = trim_string(line);
    std::string x;
    x = munch_token(line);

    // Example 1: "Live ID3D11Query at 0x0000018F64E81DA0, Refcount: 0, IntRef:
    // 1" Example 2: "Live ID3D11Buffer at 0x000001F8AF284370, Name: buffer
    // alloc#0 size=1048576, Refcount: 1, IntRef: 1"

    if (x != "Live")
      continue;

    x = munch_token(line);
    entry.type = x;

    x = munch_token(line);
    if (x != "at")
{'fraction_non_alphanumeric': 0.17105263157894737, 'fraction_numerical': 0.0443213296398892, 'mean_word_length': 3.6076555023923444, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1440641', 'n_tokens_mistral': 1172, 'n_tokens_neox': 1081, 'n_words': 247}