v8
V8 is Google’s open source high-performance JavaScript and WebAssembly engine, written in C++.
Loading...
Searching...
No Matches
string-comparator.h
Go to the documentation of this file.
1// Copyright 2019 the V8 project authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef V8_OBJECTS_STRING_COMPARATOR_H_
6#define V8_OBJECTS_STRING_COMPARATOR_H_
7
8#include "src/base/logging.h"
10#include "src/objects/string.h"
11#include "src/utils/utils.h"
12
13namespace v8 {
14namespace internal {
15
17 class State {
18 public:
19 State() : is_one_byte_(true), length_(0), buffer8_(nullptr) {}
20 State(const State&) = delete;
21 State& operator=(const State&) = delete;
22
23 void Init(Tagged<String> string,
24 const SharedStringAccessGuardIfNeeded& access_guard);
25
26 inline void VisitOneByteString(const uint8_t* chars, int length) {
27 is_one_byte_ = true;
28 buffer8_ = chars;
30 }
31
32 inline void VisitTwoByteString(const uint16_t* chars, int length) {
33 is_one_byte_ = false;
34 buffer16_ = chars;
36 }
37
38 void Advance(int consumed,
39 const SharedStringAccessGuardIfNeeded& access_guard);
40
44 union {
45 const uint8_t* buffer8_;
46 const uint16_t* buffer16_;
47 };
48 };
49
50 public:
51 inline StringComparator() = default;
54
55 template <typename Chars1, typename Chars2>
56 static inline bool Equals(State* state_1, State* state_2, int to_check) {
57 const Chars1* a = reinterpret_cast<const Chars1*>(state_1->buffer8_);
58 const Chars2* b = reinterpret_cast<const Chars2*>(state_2->buffer8_);
59 return CompareCharsEqual(a, b, to_check);
60 }
61
62 bool Equals(Tagged<String> string_1, Tagged<String> string_2,
63 const SharedStringAccessGuardIfNeeded& access_guard);
64
65 private:
68};
69
70} // namespace internal
71} // namespace v8
72
73#endif // V8_OBJECTS_STRING_COMPARATOR_H_
void VisitOneByteString(const uint8_t *chars, int length)
State & operator=(const State &)=delete
void Advance(int consumed, const SharedStringAccessGuardIfNeeded &access_guard)
void VisitTwoByteString(const uint16_t *chars, int length)
void Init(Tagged< String > string, const SharedStringAccessGuardIfNeeded &access_guard)
static bool Equals(State *state_1, State *state_2, int to_check)
StringComparator & operator=(const StringComparator &)=delete
StringComparator(const StringComparator &)=delete
bool CompareCharsEqual(const lchar *lhs, const rchar *rhs, size_t chars)
Definition utils.h:509