Coverage Report

Created: 2025-09-08 06:20

/proc/self/cwd/cpp/htmlparser/atomutil.cc
Line
Count
Source (jump to first uncovered line)
1
#include "cpp/htmlparser/atomutil.h"
2
3
#include "cpp/htmlparser/hash.h"
4
5
namespace htmlparser {
6
7
13.4M
Atom AtomUtil::ToAtom(const std::string& s) {
8
13.4M
  if (s.empty() || s.size() > kMaxAtomLength) {
9
767
    return Atom::UNKNOWN;
10
767
  }
11
12
13.4M
  uint32_t hash = Hash::FNVHash(s, kInitialHashValue);
13
13.4M
  uint32_t table_index = hash & (kNamesHashTable.size() - 1);
14
13.4M
  uint32_t atom_value = kNamesHashTable[table_index];
15
13.4M
  int atom_len = atom_value & 0xff;
16
13.4M
  if (atom_len == s.size() && ToString(atom_value) == s) {
17
4.66M
    return CastToAtom(atom_value);
18
4.66M
  }
19
20
8.75M
  table_index = (hash >> 16) & (kNamesHashTable.size() - 1);
21
8.75M
  atom_value = kNamesHashTable[table_index];
22
8.75M
  atom_len = atom_value & 0xff;
23
8.75M
  if (atom_len == s.size() && ToString(atom_value).compare(s) == 0) {
24
830k
    return CastToAtom(atom_value);
25
830k
  }
26
27
7.92M
  return Atom::UNKNOWN;
28
8.75M
}
29
30
7.99M
std::string AtomUtil::ToString(Atom a, std::string_view unknown_tag_name) {
31
7.99M
  if (a == Atom::UNKNOWN) return std::string(unknown_tag_name);
32
7.99M
  uint32_t start = static_cast<uint32_t>(a) >> 8;
33
7.99M
  uint32_t n = static_cast<uint32_t>(a) & 0xff;
34
7.99M
  if ((start + n) > kAtomText.size()) {
35
0
    return std::string(unknown_tag_name);
36
0
  }
37
7.99M
  return std::string(kAtomText.substr(start, n));
38
7.99M
}
39
40
}  // namespace htmlparser