v8
V8 is Google’s open source high-performance JavaScript and WebAssembly engine, written in C++.
Loading...
Searching...
No Matches
string-comparator.cc
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
6
8
9namespace v8 {
10namespace internal {
11
13 Tagged<String> string,
14 const SharedStringAccessGuardIfNeeded& access_guard) {
15 Tagged<ConsString> cons_string =
16 String::VisitFlat(this, string, 0, access_guard);
17 iter_.Reset(cons_string);
18 if (!cons_string.is_null()) {
19 int offset;
20 string = iter_.Next(&offset);
21 // We are resetting the iterator with zero offset, so we should never have
22 // a per-segment offset.
23 DCHECK_EQ(offset, 0);
24 String::VisitFlat(this, string, 0, access_guard);
25 }
26}
27
29 int consumed, const SharedStringAccessGuardIfNeeded& access_guard) {
30 DCHECK(consumed <= length_);
31 // Still in buffer.
32 if (length_ != consumed) {
33 if (is_one_byte_) {
34 buffer8_ += consumed;
35 } else {
36 buffer16_ += consumed;
37 }
38 length_ -= consumed;
39 return;
40 }
41 // Advance state.
42 int offset;
43 Tagged<String> next = iter_.Next(&offset);
44 DCHECK_EQ(0, offset);
45 DCHECK(!next.is_null());
46 String::VisitFlat(this, next, 0, access_guard);
47}
48
50 Tagged<String> string_1, Tagged<String> string_2,
51 const SharedStringAccessGuardIfNeeded& access_guard) {
52 int length = string_1->length();
53 state_1_.Init(string_1, access_guard);
54 state_2_.Init(string_2, access_guard);
55 while (true) {
56 int to_check = std::min(state_1_.length_, state_2_.length_);
57 DCHECK(to_check > 0 && to_check <= length);
58 bool is_equal;
61 is_equal = Equals<uint8_t, uint8_t>(&state_1_, &state_2_, to_check);
62 } else {
63 is_equal = Equals<uint8_t, uint16_t>(&state_1_, &state_2_, to_check);
64 }
65 } else {
67 is_equal = Equals<uint16_t, uint8_t>(&state_1_, &state_2_, to_check);
68 } else {
69 is_equal = Equals<uint16_t, uint16_t>(&state_1_, &state_2_, to_check);
70 }
71 }
72 // Looping done.
73 if (!is_equal) return false;
74 length -= to_check;
75 // Exit condition. Strings are equal.
76 if (length == 0) return true;
77 state_1_.Advance(to_check, access_guard);
78 state_2_.Advance(to_check, access_guard);
79 }
80}
81
82} // namespace internal
83} // namespace v8
void Reset(Tagged< ConsString > cons_string, int offset=0)
Definition string.h:1329
Tagged< String > Next(int *offset_out)
Definition string.h:1340
void Advance(int consumed, const SharedStringAccessGuardIfNeeded &access_guard)
void Init(Tagged< String > string, const SharedStringAccessGuardIfNeeded &access_guard)
static bool Equals(State *state_1, State *state_2, int to_check)
static Tagged< ConsString > VisitFlat(Visitor *visitor, Tagged< String > string, int offset=0)
V8_INLINE constexpr bool is_null() const
Definition tagged.h:502
int32_t offset
std::vector< std::string >::const_iterator iter_
const int length_
Definition mul-fft.cc:473
#define DCHECK(condition)
Definition logging.h:482
#define DCHECK_EQ(v1, v2)
Definition logging.h:485