Line data Source code
1 : // Copyright 2017 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_NAME_INL_H_
6 : #define V8_OBJECTS_NAME_INL_H_
7 :
8 : #include "src/objects/name.h"
9 :
10 : #include "src/heap/heap-write-barrier-inl.h"
11 : #include "src/objects/map-inl.h"
12 :
13 : // Has to be the last include (doesn't have include guards):
14 : #include "src/objects/object-macros.h"
15 :
16 : namespace v8 {
17 : namespace internal {
18 :
19 : OBJECT_CONSTRUCTORS_IMPL(Name, HeapObject)
20 : OBJECT_CONSTRUCTORS_IMPL(Symbol, Name)
21 :
22 : CAST_ACCESSOR(Name)
23 : CAST_ACCESSOR(Symbol)
24 :
25 157967 : ACCESSORS(Symbol, name, Object, kNameOffset)
26 16882322 : INT_ACCESSORS(Symbol, flags, kFlagsOffset)
27 15178347 : BIT_FIELD_ACCESSORS(Symbol, flags, is_private, Symbol::IsPrivateBit)
28 393 : BIT_FIELD_ACCESSORS(Symbol, flags, is_well_known_symbol,
29 : Symbol::IsWellKnownSymbolBit)
30 183 : BIT_FIELD_ACCESSORS(Symbol, flags, is_public, Symbol::IsPublicBit)
31 1526262 : BIT_FIELD_ACCESSORS(Symbol, flags, is_interesting_symbol,
32 : Symbol::IsInterestingSymbolBit)
33 :
34 : bool Symbol::is_private_name() const {
35 155957 : bool value = Symbol::IsPrivateNameBit::decode(flags());
36 : DCHECK_IMPLIES(value, is_private());
37 : return value;
38 : }
39 :
40 : void Symbol::set_is_private_name() {
41 : // TODO(gsathya): Re-order the bits to have these next to each other
42 : // and just do the bit shifts once.
43 1976 : set_flags(Symbol::IsPrivateBit::update(flags(), true));
44 988 : set_flags(Symbol::IsPrivateNameBit::update(flags(), true));
45 : }
46 :
47 : bool Name::IsUniqueName() const {
48 92758334 : uint32_t type = map()->instance_type();
49 92758334 : bool result = (type & (kIsNotStringMask | kIsNotInternalizedMask)) !=
50 : (kStringTag | kNotInternalizedTag);
51 : SLOW_DCHECK(result == HeapObject::IsUniqueName());
52 : return result;
53 : }
54 :
55 : uint32_t Name::hash_field() {
56 1954104409 : return READ_UINT32_FIELD(*this, kHashFieldOffset);
57 : }
58 :
59 : void Name::set_hash_field(uint32_t value) {
60 250398100 : WRITE_UINT32_FIELD(*this, kHashFieldOffset, value);
61 : }
62 :
63 61300 : bool Name::Equals(Name other) {
64 61300 : if (other == *this) return true;
65 158442 : if ((this->IsInternalizedString() && other->IsInternalizedString()) ||
66 53658 : this->IsSymbol() || other->IsSymbol()) {
67 : return false;
68 : }
69 9 : return String::cast(*this)->SlowEquals(String::cast(other));
70 : }
71 :
72 83978 : bool Name::Equals(Isolate* isolate, Handle<Name> one, Handle<Name> two) {
73 83978 : if (one.is_identical_to(two)) return true;
74 32622 : if ((one->IsInternalizedString() && two->IsInternalizedString()) ||
75 16339 : one->IsSymbol() || two->IsSymbol()) {
76 : return false;
77 : }
78 : return String::SlowEquals(isolate, Handle<String>::cast(one),
79 18 : Handle<String>::cast(two));
80 : }
81 :
82 : bool Name::IsHashFieldComputed(uint32_t field) {
83 1640494954 : return (field & kHashNotComputedMask) == 0;
84 : }
85 :
86 : bool Name::HasHashCode() { return IsHashFieldComputed(hash_field()); }
87 :
88 1589487330 : uint32_t Name::Hash() {
89 : // Fast case: has hash code already been computed?
90 : uint32_t field = hash_field();
91 1589487330 : if (IsHashFieldComputed(field)) return field >> kHashShift;
92 : // Slow case: compute hash code and set it. Has to be a string.
93 70374845 : return String::cast(*this)->ComputeAndSetHash();
94 : }
95 :
96 20215636 : bool Name::IsInterestingSymbol() const {
97 41957424 : return IsSymbol() && Symbol::cast(*this)->is_interesting_symbol();
98 : }
99 :
100 153088799 : bool Name::IsPrivate() {
101 321236246 : return this->IsSymbol() && Symbol::cast(*this)->is_private();
102 : }
103 :
104 18261 : bool Name::IsPrivateName() {
105 : bool is_private_name =
106 54252 : this->IsSymbol() && Symbol::cast(*this)->is_private_name();
107 : DCHECK_IMPLIES(is_private_name, IsPrivate());
108 18261 : return is_private_name;
109 : }
110 :
111 27576625 : bool Name::AsArrayIndex(uint32_t* index) {
112 55153257 : return IsString() && String::cast(*this)->AsArrayIndex(index);
113 : }
114 :
115 : // static
116 : bool Name::ContainsCachedArrayIndex(uint32_t hash) {
117 1955640 : return (hash & Name::kDoesNotContainCachedArrayIndexMask) == 0;
118 : }
119 :
120 : } // namespace internal
121 : } // namespace v8
122 :
123 : #include "src/objects/object-macros-undef.h"
124 :
125 : #endif // V8_OBJECTS_NAME_INL_H_
|