Commit aee471b2 authored by Camillo Bruni's avatar Camillo Bruni Committed by Commit Bot

[api] Avoid handles for const API functions

Handles are notorious for preventing compiler optimizations. We should
avoid them for simple const functions.

- Mark more API functions const
- Mark more String functions const

Bug: v8:11195, chromium:808503, v8:11263
Change-Id: I9940e85600bc7d19027039d807b3313e2dcccdc7
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2575065Reviewed-by: 's avatarLeszek Swirski <leszeks@chromium.org>
Commit-Queue: Camillo Bruni <cbruni@chromium.org>
Cr-Commit-Position: refs/heads/master@{#73159}
parent e3d4d9b4
...@@ -1491,7 +1491,7 @@ class V8_EXPORT UnboundScript { ...@@ -1491,7 +1491,7 @@ class V8_EXPORT UnboundScript {
*/ */
Local<Script> BindToCurrentContext(); Local<Script> BindToCurrentContext();
int GetId(); int GetId() const;
Local<Value> GetScriptName(); Local<Value> GetScriptName();
/** /**
...@@ -1701,7 +1701,7 @@ class V8_EXPORT Module : public Data { ...@@ -1701,7 +1701,7 @@ class V8_EXPORT Module : public Data {
* *
* The module must be a SourceTextModule and must not have a kErrored status. * The module must be a SourceTextModule and must not have a kErrored status.
*/ */
int ScriptId(); int ScriptId() const;
/** /**
* Returns whether this module or any of its requested modules is async, * Returns whether this module or any of its requested modules is async,
...@@ -3525,12 +3525,12 @@ class V8_EXPORT String : public Name { ...@@ -3525,12 +3525,12 @@ class V8_EXPORT String : public Name {
/** /**
* Returns true if this string can be made external. * Returns true if this string can be made external.
*/ */
bool CanMakeExternal(); bool CanMakeExternal() const;
/** /**
* Returns true if the strings values are equal. Same as JS ==/===. * Returns true if the strings values are equal. Same as JS ==/===.
*/ */
bool StringEquals(Local<String> str); bool StringEquals(Local<String> str) const;
/** /**
* Converts an object to a UTF-8-encoded character array. Useful if * Converts an object to a UTF-8-encoded character array. Useful if
...@@ -4137,7 +4137,7 @@ class V8_EXPORT Object : public Value { ...@@ -4137,7 +4137,7 @@ class V8_EXPORT Object : public Value {
Maybe<bool> SetIntegrityLevel(Local<Context> context, IntegrityLevel level); Maybe<bool> SetIntegrityLevel(Local<Context> context, IntegrityLevel level);
/** Gets the number of internal fields for this Object. */ /** Gets the number of internal fields for this Object. */
int InternalFieldCount(); int InternalFieldCount() const;
/** Same as above, but works for PersistentBase. */ /** Same as above, but works for PersistentBase. */
V8_INLINE static int InternalFieldCount( V8_INLINE static int InternalFieldCount(
...@@ -4247,10 +4247,10 @@ class V8_EXPORT Object : public Value { ...@@ -4247,10 +4247,10 @@ class V8_EXPORT Object : public Value {
Local<Context> context, Local<Name> key); Local<Context> context, Local<Name> key);
/** Tests for a named lookup interceptor.*/ /** Tests for a named lookup interceptor.*/
bool HasNamedLookupInterceptor(); bool HasNamedLookupInterceptor() const;
/** Tests for an index lookup interceptor.*/ /** Tests for an index lookup interceptor.*/
bool HasIndexedLookupInterceptor(); bool HasIndexedLookupInterceptor() const;
/** /**
* Returns the identity hash for this object. The current implementation * Returns the identity hash for this object. The current implementation
...@@ -4290,12 +4290,12 @@ class V8_EXPORT Object : public Value { ...@@ -4290,12 +4290,12 @@ class V8_EXPORT Object : public Value {
* ObjectTemplate::SetCallAsFunctionHandler method. * ObjectTemplate::SetCallAsFunctionHandler method.
* When an Object is callable this method returns true. * When an Object is callable this method returns true.
*/ */
bool IsCallable(); bool IsCallable() const;
/** /**
* True if this object is a constructor. * True if this object is a constructor.
*/ */
bool IsConstructor(); bool IsConstructor() const;
/** /**
* True if this object can carry information relevant to the embedder in its * True if this object can carry information relevant to the embedder in its
...@@ -4304,14 +4304,14 @@ class V8_EXPORT Object : public Value { ...@@ -4304,14 +4304,14 @@ class V8_EXPORT Object : public Value {
* V8 automatically adds internal fields at compile time, such as e.g. * V8 automatically adds internal fields at compile time, such as e.g.
* v8::ArrayBuffer. * v8::ArrayBuffer.
*/ */
bool IsApiWrapper(); bool IsApiWrapper() const;
/** /**
* True if this object was created from an object template which was marked * True if this object was created from an object template which was marked
* as undetectable. See v8::ObjectTemplate::MarkAsUndetectable for more * as undetectable. See v8::ObjectTemplate::MarkAsUndetectable for more
* information. * information.
*/ */
bool IsUndetectable(); bool IsUndetectable() const;
/** /**
* Call an Object as a function if a callback is set by the * Call an Object as a function if a callback is set by the
...@@ -4370,7 +4370,7 @@ class V8_EXPORT Object : public Value { ...@@ -4370,7 +4370,7 @@ class V8_EXPORT Object : public Value {
* *
* See also: v8::ObjectTemplate::SetCodeLike * See also: v8::ObjectTemplate::SetCodeLike
*/ */
bool IsCodeLike(Isolate* isolate); bool IsCodeLike(Isolate* isolate) const;
private: private:
Object(); Object();
...@@ -4868,7 +4868,7 @@ class V8_EXPORT Promise : public Object { ...@@ -4868,7 +4868,7 @@ class V8_EXPORT Promise : public Object {
* Returns true if the promise has at least one derived promise, and * Returns true if the promise has at least one derived promise, and
* therefore resolve/reject handlers (including default handler). * therefore resolve/reject handlers (including default handler).
*/ */
bool HasHandler(); bool HasHandler() const;
/** /**
* Returns the content of the [[PromiseResult]] field. The Promise must not * Returns the content of the [[PromiseResult]] field. The Promise must not
...@@ -4976,7 +4976,7 @@ class V8_EXPORT Proxy : public Object { ...@@ -4976,7 +4976,7 @@ class V8_EXPORT Proxy : public Object {
public: public:
Local<Value> GetTarget(); Local<Value> GetTarget();
Local<Value> GetHandler(); Local<Value> GetHandler();
bool IsRevoked(); bool IsRevoked() const;
void Revoke(); void Revoke();
/** /**
...@@ -7168,7 +7168,7 @@ class V8_EXPORT ObjectTemplate : public Template { ...@@ -7168,7 +7168,7 @@ class V8_EXPORT ObjectTemplate : public Template {
* Gets the number of internal fields for objects generated from * Gets the number of internal fields for objects generated from
* this template. * this template.
*/ */
int InternalFieldCount(); int InternalFieldCount() const;
/** /**
* Sets the number of internal fields for objects generated from * Sets the number of internal fields for objects generated from
...@@ -7179,7 +7179,7 @@ class V8_EXPORT ObjectTemplate : public Template { ...@@ -7179,7 +7179,7 @@ class V8_EXPORT ObjectTemplate : public Template {
/** /**
* Returns true if the object will be an immutable prototype exotic object. * Returns true if the object will be an immutable prototype exotic object.
*/ */
bool IsImmutableProto(); bool IsImmutableProto() const;
/** /**
* Makes the ObjectTemplate for an immutable prototype exotic object, with an * Makes the ObjectTemplate for an immutable prototype exotic object, with an
...@@ -7197,7 +7197,7 @@ class V8_EXPORT ObjectTemplate : public Template { ...@@ -7197,7 +7197,7 @@ class V8_EXPORT ObjectTemplate : public Template {
* Reference: https://github.com/tc39/proposal-dynamic-code-brand-checks * Reference: https://github.com/tc39/proposal-dynamic-code-brand-checks
*/ */
void SetCodeLike(); void SetCodeLike();
bool IsCodeLike(); bool IsCodeLike() const;
V8_INLINE static ObjectTemplate* Cast(Data* data); V8_INLINE static ObjectTemplate* Cast(Data* data);
...@@ -10735,7 +10735,7 @@ class V8_EXPORT Context : public Data { ...@@ -10735,7 +10735,7 @@ class V8_EXPORT Context : public Data {
* Returns true if code generation from strings is allowed for the context. * Returns true if code generation from strings is allowed for the context.
* For more details see AllowCodeGenerationFromStrings(bool) documentation. * For more details see AllowCodeGenerationFromStrings(bool) documentation.
*/ */
bool IsCodeGenerationFromStringsAllowed(); bool IsCodeGenerationFromStringsAllowed() const;
/** /**
* Sets the error description for the exception that is thrown when * Sets the error description for the exception that is thrown when
......
This diff is collapsed.
...@@ -133,49 +133,51 @@ StringShape::StringShape(InstanceType t) : type_(static_cast<uint32_t>(t)) { ...@@ -133,49 +133,51 @@ StringShape::StringShape(InstanceType t) : type_(static_cast<uint32_t>(t)) {
DCHECK_EQ(type_ & kIsNotStringMask, kStringTag); DCHECK_EQ(type_ & kIsNotStringMask, kStringTag);
} }
bool StringShape::IsInternalized() { bool StringShape::IsInternalized() const {
DCHECK(valid()); DCHECK(valid());
STATIC_ASSERT(kNotInternalizedTag != 0); STATIC_ASSERT(kNotInternalizedTag != 0);
return (type_ & (kIsNotStringMask | kIsNotInternalizedMask)) == return (type_ & (kIsNotStringMask | kIsNotInternalizedMask)) ==
(kStringTag | kInternalizedTag); (kStringTag | kInternalizedTag);
} }
bool StringShape::IsCons() { bool StringShape::IsCons() const {
return (type_ & kStringRepresentationMask) == kConsStringTag; return (type_ & kStringRepresentationMask) == kConsStringTag;
} }
bool StringShape::IsThin() { bool StringShape::IsThin() const {
return (type_ & kStringRepresentationMask) == kThinStringTag; return (type_ & kStringRepresentationMask) == kThinStringTag;
} }
bool StringShape::IsSliced() { bool StringShape::IsSliced() const {
return (type_ & kStringRepresentationMask) == kSlicedStringTag; return (type_ & kStringRepresentationMask) == kSlicedStringTag;
} }
bool StringShape::IsIndirect() { bool StringShape::IsIndirect() const {
return (type_ & kIsIndirectStringMask) == kIsIndirectStringTag; return (type_ & kIsIndirectStringMask) == kIsIndirectStringTag;
} }
bool StringShape::IsExternal() { bool StringShape::IsExternal() const {
return (type_ & kStringRepresentationMask) == kExternalStringTag; return (type_ & kStringRepresentationMask) == kExternalStringTag;
} }
bool StringShape::IsSequential() { bool StringShape::IsSequential() const {
return (type_ & kStringRepresentationMask) == kSeqStringTag; return (type_ & kStringRepresentationMask) == kSeqStringTag;
} }
bool StringShape::IsUncachedExternal() { bool StringShape::IsUncachedExternal() const {
return (type_ & kUncachedExternalStringMask) == kUncachedExternalStringTag; return (type_ & kUncachedExternalStringMask) == kUncachedExternalStringTag;
} }
StringRepresentationTag StringShape::representation_tag() { StringRepresentationTag StringShape::representation_tag() const {
uint32_t tag = (type_ & kStringRepresentationMask); uint32_t tag = (type_ & kStringRepresentationMask);
return static_cast<StringRepresentationTag>(tag); return static_cast<StringRepresentationTag>(tag);
} }
uint32_t StringShape::encoding_tag() { return type_ & kStringEncodingMask; } uint32_t StringShape::encoding_tag() const {
return type_ & kStringEncodingMask;
}
uint32_t StringShape::full_representation_tag() { uint32_t StringShape::full_representation_tag() const {
return (type_ & (kStringRepresentationMask | kStringEncodingMask)); return (type_ & (kStringRepresentationMask | kStringEncodingMask));
} }
...@@ -185,15 +187,15 @@ STATIC_ASSERT((kStringRepresentationMask | kStringEncodingMask) == ...@@ -185,15 +187,15 @@ STATIC_ASSERT((kStringRepresentationMask | kStringEncodingMask) ==
STATIC_ASSERT(static_cast<uint32_t>(kStringEncodingMask) == STATIC_ASSERT(static_cast<uint32_t>(kStringEncodingMask) ==
Internals::kStringEncodingMask); Internals::kStringEncodingMask);
bool StringShape::IsSequentialOneByte() { bool StringShape::IsSequentialOneByte() const {
return full_representation_tag() == (kSeqStringTag | kOneByteStringTag); return full_representation_tag() == (kSeqStringTag | kOneByteStringTag);
} }
bool StringShape::IsSequentialTwoByte() { bool StringShape::IsSequentialTwoByte() const {
return full_representation_tag() == (kSeqStringTag | kTwoByteStringTag); return full_representation_tag() == (kSeqStringTag | kTwoByteStringTag);
} }
bool StringShape::IsExternalOneByte() { bool StringShape::IsExternalOneByte() const {
return full_representation_tag() == (kExternalStringTag | kOneByteStringTag); return full_representation_tag() == (kExternalStringTag | kOneByteStringTag);
} }
...@@ -202,7 +204,7 @@ STATIC_ASSERT((kExternalStringTag | kOneByteStringTag) == ...@@ -202,7 +204,7 @@ STATIC_ASSERT((kExternalStringTag | kOneByteStringTag) ==
STATIC_ASSERT(v8::String::ONE_BYTE_ENCODING == kOneByteStringTag); STATIC_ASSERT(v8::String::ONE_BYTE_ENCODING == kOneByteStringTag);
bool StringShape::IsExternalTwoByte() { bool StringShape::IsExternalTwoByte() const {
return full_representation_tag() == (kExternalStringTag | kTwoByteStringTag); return full_representation_tag() == (kExternalStringTag | kTwoByteStringTag);
} }
...@@ -298,7 +300,7 @@ bool String::IsOneByteRepresentationUnderneath(String string) { ...@@ -298,7 +300,7 @@ bool String::IsOneByteRepresentationUnderneath(String string) {
} }
} }
uc32 FlatStringReader::Get(int index) { uc32 FlatStringReader::Get(int index) const {
if (is_one_byte_) { if (is_one_byte_) {
return Get<uint8_t>(index); return Get<uint8_t>(index);
} else { } else {
...@@ -307,7 +309,7 @@ uc32 FlatStringReader::Get(int index) { ...@@ -307,7 +309,7 @@ uc32 FlatStringReader::Get(int index) {
} }
template <typename Char> template <typename Char>
Char FlatStringReader::Get(int index) { Char FlatStringReader::Get(int index) const {
DCHECK_EQ(is_one_byte_, sizeof(Char) == 1); DCHECK_EQ(is_one_byte_, sizeof(Char) == 1);
DCHECK(0 <= index && index < length_); DCHECK(0 <= index && index < length_);
if (sizeof(Char) == 1) { if (sizeof(Char) == 1) {
...@@ -432,7 +434,7 @@ class SeqSubStringKey final : public StringTableKey { ...@@ -432,7 +434,7 @@ class SeqSubStringKey final : public StringTableKey {
using SeqOneByteSubStringKey = SeqSubStringKey<SeqOneByteString>; using SeqOneByteSubStringKey = SeqSubStringKey<SeqOneByteString>;
using SeqTwoByteSubStringKey = SeqSubStringKey<SeqTwoByteString>; using SeqTwoByteSubStringKey = SeqSubStringKey<SeqTwoByteString>;
bool String::Equals(String other) { bool String::Equals(String other) const {
if (other == *this) return true; if (other == *this) return true;
if (this->IsInternalizedString() && other.IsInternalizedString()) { if (this->IsInternalizedString() && other.IsInternalizedString()) {
return false; return false;
...@@ -440,6 +442,7 @@ bool String::Equals(String other) { ...@@ -440,6 +442,7 @@ bool String::Equals(String other) {
return SlowEquals(other); return SlowEquals(other);
} }
// static
bool String::Equals(Isolate* isolate, Handle<String> one, Handle<String> two) { bool String::Equals(Isolate* isolate, Handle<String> one, Handle<String> two) {
if (one.is_identical_to(two)) return true; if (one.is_identical_to(two)) return true;
if (one->IsInternalizedString() && two->IsInternalizedString()) { if (one->IsInternalizedString() && two->IsInternalizedString()) {
...@@ -539,7 +542,7 @@ bool String::IsEqualToImpl( ...@@ -539,7 +542,7 @@ bool String::IsEqualToImpl(
bool String::IsOneByteEqualTo(Vector<const char> str) { return IsEqualTo(str); } bool String::IsOneByteEqualTo(Vector<const char> str) { return IsEqualTo(str); }
template <typename Char> template <typename Char>
const Char* String::GetChars(const DisallowGarbageCollection& no_gc) { const Char* String::GetChars(const DisallowGarbageCollection& no_gc) const {
DCHECK(!SharedStringAccessGuardIfNeeded::IsNeeded(*this)); DCHECK(!SharedStringAccessGuardIfNeeded::IsNeeded(*this));
return StringShape(*this).IsExternal() return StringShape(*this).IsExternal()
? CharTraits<Char>::ExternalString::cast(*this).GetChars() ? CharTraits<Char>::ExternalString::cast(*this).GetChars()
...@@ -549,7 +552,7 @@ const Char* String::GetChars(const DisallowGarbageCollection& no_gc) { ...@@ -549,7 +552,7 @@ const Char* String::GetChars(const DisallowGarbageCollection& no_gc) {
template <typename Char> template <typename Char>
const Char* String::GetChars( const Char* String::GetChars(
const DisallowGarbageCollection& no_gc, const DisallowGarbageCollection& no_gc,
const SharedStringAccessGuardIfNeeded& access_guard) { const SharedStringAccessGuardIfNeeded& access_guard) const {
return StringShape(*this).IsExternal() return StringShape(*this).IsExternal()
? CharTraits<Char>::ExternalString::cast(*this).GetChars() ? CharTraits<Char>::ExternalString::cast(*this).GetChars()
: CharTraits<Char>::String::cast(*this).GetChars(no_gc, : CharTraits<Char>::String::cast(*this).GetChars(no_gc,
...@@ -580,17 +583,17 @@ Handle<String> String::Flatten(LocalIsolate* isolate, Handle<String> string, ...@@ -580,17 +583,17 @@ Handle<String> String::Flatten(LocalIsolate* isolate, Handle<String> string,
return string; return string;
} }
uint16_t String::Get(int index, Isolate* isolate) { uint16_t String::Get(int index, Isolate* isolate) const {
DCHECK(!SharedStringAccessGuardIfNeeded::IsNeeded(*this)); DCHECK(!SharedStringAccessGuardIfNeeded::IsNeeded(*this));
return GetImpl(index); return GetImpl(index);
} }
uint16_t String::Get(int index, LocalIsolate* local_isolate) { uint16_t String::Get(int index, LocalIsolate* local_isolate) const {
SharedStringAccessGuardIfNeeded scope(local_isolate); SharedStringAccessGuardIfNeeded scope(local_isolate);
return GetImpl(index); return GetImpl(index);
} }
uint16_t String::GetImpl(int index) { uint16_t String::GetImpl(int index) const {
DCHECK(index >= 0 && index < length()); DCHECK(index >= 0 && index < length());
class StringGetDispatcher : public AllStatic { class StringGetDispatcher : public AllStatic {
...@@ -619,12 +622,12 @@ void String::Set(int index, uint16_t value) { ...@@ -619,12 +622,12 @@ void String::Set(int index, uint16_t value) {
: SeqTwoByteString::cast(*this).SeqTwoByteStringSet(index, value); : SeqTwoByteString::cast(*this).SeqTwoByteStringSet(index, value);
} }
bool String::IsFlat() { bool String::IsFlat() const {
if (!StringShape(*this).IsCons()) return true; if (!StringShape(*this).IsCons()) return true;
return ConsString::cast(*this).second().length() == 0; return ConsString::cast(*this).second().length() == 0;
} }
String String::GetUnderlying() { String String::GetUnderlying() const {
// Giving direct access to underlying string only makes sense if the // Giving direct access to underlying string only makes sense if the
// wrapping string is already flattened. // wrapping string is already flattened.
DCHECK(this->IsFlat()); DCHECK(this->IsFlat());
...@@ -728,7 +731,7 @@ uint32_t String::ToValidIndex(Object number) { ...@@ -728,7 +731,7 @@ uint32_t String::ToValidIndex(Object number) {
return index; return index;
} }
uint8_t SeqOneByteString::Get(int index) { uint8_t SeqOneByteString::Get(int index) const {
DCHECK(index >= 0 && index < length()); DCHECK(index >= 0 && index < length());
return ReadField<byte>(kHeaderSize + index * kCharSize); return ReadField<byte>(kHeaderSize + index * kCharSize);
} }
...@@ -738,11 +741,12 @@ void SeqOneByteString::SeqOneByteStringSet(int index, uint16_t value) { ...@@ -738,11 +741,12 @@ void SeqOneByteString::SeqOneByteStringSet(int index, uint16_t value) {
WriteField<byte>(kHeaderSize + index * kCharSize, static_cast<byte>(value)); WriteField<byte>(kHeaderSize + index * kCharSize, static_cast<byte>(value));
} }
Address SeqOneByteString::GetCharsAddress() { Address SeqOneByteString::GetCharsAddress() const {
return field_address(kHeaderSize); return field_address(kHeaderSize);
} }
uint8_t* SeqOneByteString::GetChars(const DisallowGarbageCollection& no_gc) { uint8_t* SeqOneByteString::GetChars(
const DisallowGarbageCollection& no_gc) const {
USE(no_gc); USE(no_gc);
DCHECK(!SharedStringAccessGuardIfNeeded::IsNeeded(*this)); DCHECK(!SharedStringAccessGuardIfNeeded::IsNeeded(*this));
return reinterpret_cast<uint8_t*>(GetCharsAddress()); return reinterpret_cast<uint8_t*>(GetCharsAddress());
...@@ -750,17 +754,17 @@ uint8_t* SeqOneByteString::GetChars(const DisallowGarbageCollection& no_gc) { ...@@ -750,17 +754,17 @@ uint8_t* SeqOneByteString::GetChars(const DisallowGarbageCollection& no_gc) {
uint8_t* SeqOneByteString::GetChars( uint8_t* SeqOneByteString::GetChars(
const DisallowGarbageCollection& no_gc, const DisallowGarbageCollection& no_gc,
const SharedStringAccessGuardIfNeeded& access_guard) { const SharedStringAccessGuardIfNeeded& access_guard) const {
USE(no_gc); USE(no_gc);
USE(access_guard); USE(access_guard);
return reinterpret_cast<uint8_t*>(GetCharsAddress()); return reinterpret_cast<uint8_t*>(GetCharsAddress());
} }
Address SeqTwoByteString::GetCharsAddress() { Address SeqTwoByteString::GetCharsAddress() const {
return field_address(kHeaderSize); return field_address(kHeaderSize);
} }
uc16* SeqTwoByteString::GetChars(const DisallowGarbageCollection& no_gc) { uc16* SeqTwoByteString::GetChars(const DisallowGarbageCollection& no_gc) const {
USE(no_gc); USE(no_gc);
DCHECK(!SharedStringAccessGuardIfNeeded::IsNeeded(*this)); DCHECK(!SharedStringAccessGuardIfNeeded::IsNeeded(*this));
return reinterpret_cast<uc16*>(GetCharsAddress()); return reinterpret_cast<uc16*>(GetCharsAddress());
...@@ -768,13 +772,13 @@ uc16* SeqTwoByteString::GetChars(const DisallowGarbageCollection& no_gc) { ...@@ -768,13 +772,13 @@ uc16* SeqTwoByteString::GetChars(const DisallowGarbageCollection& no_gc) {
uc16* SeqTwoByteString::GetChars( uc16* SeqTwoByteString::GetChars(
const DisallowGarbageCollection& no_gc, const DisallowGarbageCollection& no_gc,
const SharedStringAccessGuardIfNeeded& access_guard) { const SharedStringAccessGuardIfNeeded& access_guard) const {
USE(no_gc); USE(no_gc);
USE(access_guard); USE(access_guard);
return reinterpret_cast<uc16*>(GetCharsAddress()); return reinterpret_cast<uc16*>(GetCharsAddress());
} }
uint16_t SeqTwoByteString::Get(int index) { uint16_t SeqTwoByteString::Get(int index) const {
DCHECK(index >= 0 && index < length()); DCHECK(index >= 0 && index < length());
return ReadField<uint16_t>(kHeaderSize + index * kShortSize); return ReadField<uint16_t>(kHeaderSize + index * kShortSize);
} }
...@@ -901,7 +905,7 @@ void ExternalOneByteString::set_resource( ...@@ -901,7 +905,7 @@ void ExternalOneByteString::set_resource(
if (resource != nullptr) update_data_cache(isolate); if (resource != nullptr) update_data_cache(isolate);
} }
const uint8_t* ExternalOneByteString::GetChars() { const uint8_t* ExternalOneByteString::GetChars() const {
DisallowGarbageCollection no_gc; DisallowGarbageCollection no_gc;
if (is_uncached()) { if (is_uncached()) {
if (resource()->IsCacheable()) { if (resource()->IsCacheable()) {
...@@ -923,7 +927,7 @@ const uint8_t* ExternalOneByteString::GetChars() { ...@@ -923,7 +927,7 @@ const uint8_t* ExternalOneByteString::GetChars() {
return reinterpret_cast<const uint8_t*>(resource()->data()); return reinterpret_cast<const uint8_t*>(resource()->data());
} }
uint8_t ExternalOneByteString::Get(int index) { uint8_t ExternalOneByteString::Get(int index) const {
DCHECK(index >= 0 && index < length()); DCHECK(index >= 0 && index < length());
return GetChars()[index]; return GetChars()[index];
} }
...@@ -966,7 +970,7 @@ void ExternalTwoByteString::set_resource( ...@@ -966,7 +970,7 @@ void ExternalTwoByteString::set_resource(
if (resource != nullptr) update_data_cache(isolate); if (resource != nullptr) update_data_cache(isolate);
} }
const uint16_t* ExternalTwoByteString::GetChars() { const uint16_t* ExternalTwoByteString::GetChars() const {
DisallowGarbageCollection no_gc; DisallowGarbageCollection no_gc;
if (is_uncached()) { if (is_uncached()) {
if (resource()->IsCacheable()) { if (resource()->IsCacheable()) {
...@@ -988,7 +992,7 @@ const uint16_t* ExternalTwoByteString::GetChars() { ...@@ -988,7 +992,7 @@ const uint16_t* ExternalTwoByteString::GetChars() {
return resource()->data(); return resource()->data();
} }
uint16_t ExternalTwoByteString::Get(int index) { uint16_t ExternalTwoByteString::Get(int index) const {
DCHECK(index >= 0 && index < length()); DCHECK(index >= 0 && index < length());
return GetChars()[index]; return GetChars()[index];
} }
......
...@@ -773,7 +773,7 @@ template Handle<FixedArray> String::CalculateLineEnds(LocalIsolate* isolate, ...@@ -773,7 +773,7 @@ template Handle<FixedArray> String::CalculateLineEnds(LocalIsolate* isolate,
Handle<String> src, Handle<String> src,
bool include_ending_line); bool include_ending_line);
bool String::SlowEquals(String other) { bool String::SlowEquals(String other) const {
DisallowGarbageCollection no_gc; DisallowGarbageCollection no_gc;
// Fast check: negative check with lengths. // Fast check: negative check with lengths.
int len = length(); int len = length();
...@@ -825,6 +825,7 @@ bool String::SlowEquals(String other) { ...@@ -825,6 +825,7 @@ bool String::SlowEquals(String other) {
return comparator.Equals(*this, other); return comparator.Equals(*this, other);
} }
// static
bool String::SlowEquals(Isolate* isolate, Handle<String> one, bool String::SlowEquals(Isolate* isolate, Handle<String> one,
Handle<String> two) { Handle<String> two) {
// Fast check: negative check with lengths. // Fast check: negative check with lengths.
...@@ -1437,7 +1438,7 @@ void SeqTwoByteString::clear_padding() { ...@@ -1437,7 +1438,7 @@ void SeqTwoByteString::clear_padding() {
SizeFor(length()) - data_size); SizeFor(length()) - data_size);
} }
uint16_t ConsString::Get(int index) { uint16_t ConsString::Get(int index) const {
DCHECK(index >= 0 && index < this->length()); DCHECK(index >= 0 && index < this->length());
// Check for a flattened cons string // Check for a flattened cons string
...@@ -1466,9 +1467,11 @@ uint16_t ConsString::Get(int index) { ...@@ -1466,9 +1467,11 @@ uint16_t ConsString::Get(int index) {
UNREACHABLE(); UNREACHABLE();
} }
uint16_t ThinString::Get(int index) { return actual().Get(index); } uint16_t ThinString::Get(int index) const { return actual().Get(index); }
uint16_t SlicedString::Get(int index) { return parent().Get(offset() + index); } uint16_t SlicedString::Get(int index) const {
return parent().Get(offset() + index);
}
int ExternalString::ExternalPayloadSize() const { int ExternalString::ExternalPayloadSize() const {
int length_multiplier = IsTwoByteRepresentation() ? i::kShortSize : kCharSize; int length_multiplier = IsTwoByteRepresentation() ? i::kShortSize : kCharSize;
......
...@@ -44,25 +44,25 @@ class StringShape { ...@@ -44,25 +44,25 @@ class StringShape {
inline explicit StringShape(const String s); inline explicit StringShape(const String s);
inline explicit StringShape(Map s); inline explicit StringShape(Map s);
inline explicit StringShape(InstanceType t); inline explicit StringShape(InstanceType t);
inline bool IsSequential(); inline bool IsSequential() const;
inline bool IsExternal(); inline bool IsExternal() const;
inline bool IsCons(); inline bool IsCons() const;
inline bool IsSliced(); inline bool IsSliced() const;
inline bool IsThin(); inline bool IsThin() const;
inline bool IsIndirect(); inline bool IsIndirect() const;
inline bool IsUncachedExternal(); inline bool IsUncachedExternal() const;
inline bool IsExternalOneByte(); inline bool IsExternalOneByte() const;
inline bool IsExternalTwoByte(); inline bool IsExternalTwoByte() const;
inline bool IsSequentialOneByte(); inline bool IsSequentialOneByte() const;
inline bool IsSequentialTwoByte(); inline bool IsSequentialTwoByte() const;
inline bool IsInternalized(); inline bool IsInternalized() const;
inline StringRepresentationTag representation_tag(); inline StringRepresentationTag representation_tag() const;
inline uint32_t encoding_tag(); inline uint32_t encoding_tag() const;
inline uint32_t full_representation_tag(); inline uint32_t full_representation_tag() const;
#ifdef DEBUG #ifdef DEBUG
inline uint32_t type() { return type_; } inline uint32_t type() const { return type_; }
inline void invalidate() { valid_ = false; } inline void invalidate() { valid_ = false; }
inline bool valid() { return valid_; } inline bool valid() const { return valid_; }
#else #else
inline void invalidate() {} inline void invalidate() {}
#endif #endif
...@@ -181,13 +181,13 @@ class String : public TorqueGeneratedString<String, Name> { ...@@ -181,13 +181,13 @@ class String : public TorqueGeneratedString<String, Name> {
// SharedStringAccessGuard is not needed (i.e. on the main thread or on // SharedStringAccessGuard is not needed (i.e. on the main thread or on
// read-only strings). // read-only strings).
template <typename Char> template <typename Char>
inline const Char* GetChars(const DisallowGarbageCollection& no_gc); inline const Char* GetChars(const DisallowGarbageCollection& no_gc) const;
// Get chars from sequential or external strings. // Get chars from sequential or external strings.
template <typename Char> template <typename Char>
inline const Char* GetChars( inline const Char* GetChars(
const DisallowGarbageCollection& no_gc, const DisallowGarbageCollection& no_gc,
const SharedStringAccessGuardIfNeeded& access_guard); const SharedStringAccessGuardIfNeeded& access_guard) const;
// Returns the address of the character at an offset into this string. // Returns the address of the character at an offset into this string.
// Requires: this->IsFlat() // Requires: this->IsFlat()
...@@ -217,8 +217,8 @@ class String : public TorqueGeneratedString<String, Name> { ...@@ -217,8 +217,8 @@ class String : public TorqueGeneratedString<String, Name> {
// to this method are not efficient unless the string is flat. // to this method are not efficient unless the string is flat.
// If it is called from a background thread, the LocalIsolate version should // If it is called from a background thread, the LocalIsolate version should
// be used. // be used.
V8_INLINE uint16_t Get(int index, Isolate* isolate = nullptr); V8_INLINE uint16_t Get(int index, Isolate* isolate = nullptr) const;
V8_INLINE uint16_t Get(int index, LocalIsolate* local_isolate); V8_INLINE uint16_t Get(int index, LocalIsolate* local_isolate) const;
// ES6 section 7.1.3.1 ToNumber Applied to the String Type // ES6 section 7.1.3.1 ToNumber Applied to the String Type
static Handle<Object> ToNumber(Isolate* isolate, Handle<String> subject); static Handle<Object> ToNumber(Isolate* isolate, Handle<String> subject);
...@@ -253,7 +253,7 @@ class String : public TorqueGeneratedString<String, Name> { ...@@ -253,7 +253,7 @@ class String : public TorqueGeneratedString<String, Name> {
// Returns the parent of a sliced string or first part of a flat cons string. // Returns the parent of a sliced string or first part of a flat cons string.
// Requires: StringShape(this).IsIndirect() && this->IsFlat() // Requires: StringShape(this).IsIndirect() && this->IsFlat()
inline String GetUnderlying(); inline String GetUnderlying() const;
// String relational comparison, implemented according to ES6 section 7.2.11 // String relational comparison, implemented according to ES6 section 7.2.11
// Abstract Relational Comparison (step 5): The comparison of Strings uses a // Abstract Relational Comparison (step 5): The comparison of Strings uses a
...@@ -314,7 +314,7 @@ class String : public TorqueGeneratedString<String, Name> { ...@@ -314,7 +314,7 @@ class String : public TorqueGeneratedString<String, Name> {
int start_index = 0); int start_index = 0);
// String equality operations. // String equality operations.
inline bool Equals(String other); inline bool Equals(String other) const;
inline static bool Equals(Isolate* isolate, Handle<String> one, inline static bool Equals(Isolate* isolate, Handle<String> one,
Handle<String> two); Handle<String> two);
...@@ -412,7 +412,7 @@ class String : public TorqueGeneratedString<String, Name> { ...@@ -412,7 +412,7 @@ class String : public TorqueGeneratedString<String, Name> {
DECL_PRINTER(String) DECL_PRINTER(String)
DECL_VERIFIER(String) DECL_VERIFIER(String)
inline bool IsFlat(); inline bool IsFlat() const;
// Max char codes. // Max char codes.
static const int32_t kMaxOneByteCharCode = unibrow::Latin1::kMaxChar; static const int32_t kMaxOneByteCharCode = unibrow::Latin1::kMaxChar;
...@@ -534,7 +534,7 @@ class String : public TorqueGeneratedString<String, Name> { ...@@ -534,7 +534,7 @@ class String : public TorqueGeneratedString<String, Name> {
friend class InternalizedStringKey; friend class InternalizedStringKey;
// Implementation of the Get() public methods. Do not use directly. // Implementation of the Get() public methods. Do not use directly.
V8_INLINE uint16_t GetImpl(int index); V8_INLINE uint16_t GetImpl(int index) const;
// Implementation of the IsEqualTo() public methods. Do not use directly. // Implementation of the IsEqualTo() public methods. Do not use directly.
template <EqualityType kEqType, typename Char> template <EqualityType kEqType, typename Char>
...@@ -547,7 +547,7 @@ class String : public TorqueGeneratedString<String, Name> { ...@@ -547,7 +547,7 @@ class String : public TorqueGeneratedString<String, Name> {
// Slow case of String::Equals. This implementation works on any strings // Slow case of String::Equals. This implementation works on any strings
// but it is most efficient on strings that are almost flat. // but it is most efficient on strings that are almost flat.
V8_EXPORT_PRIVATE bool SlowEquals(String other); V8_EXPORT_PRIVATE bool SlowEquals(String other) const;
V8_EXPORT_PRIVATE static bool SlowEquals(Isolate* isolate, Handle<String> one, V8_EXPORT_PRIVATE static bool SlowEquals(Isolate* isolate, Handle<String> one,
Handle<String> two); Handle<String> two);
...@@ -619,20 +619,21 @@ class SeqOneByteString ...@@ -619,20 +619,21 @@ class SeqOneByteString
using Char = uint8_t; using Char = uint8_t;
// Dispatched behavior. // Dispatched behavior.
inline uint8_t Get(int index); inline uint8_t Get(int index) const;
inline void SeqOneByteStringSet(int index, uint16_t value); inline void SeqOneByteStringSet(int index, uint16_t value);
// Get the address of the characters in this string. // Get the address of the characters in this string.
inline Address GetCharsAddress(); inline Address GetCharsAddress() const;
// Get a pointer to the characters of the string. May only be called when a // Get a pointer to the characters of the string. May only be called when a
// SharedStringAccessGuard is not needed (i.e. on the main thread or on // SharedStringAccessGuard is not needed (i.e. on the main thread or on
// read-only strings). // read-only strings).
inline uint8_t* GetChars(const DisallowGarbageCollection& no_gc); inline uint8_t* GetChars(const DisallowGarbageCollection& no_gc) const;
// Get a pointer to the characters of the string. // Get a pointer to the characters of the string.
inline uint8_t* GetChars(const DisallowGarbageCollection& no_gc, inline uint8_t* GetChars(
const SharedStringAccessGuardIfNeeded& access_guard); const DisallowGarbageCollection& no_gc,
const SharedStringAccessGuardIfNeeded& access_guard) const;
// Clear uninitialized padding space. This ensures that the snapshot content // Clear uninitialized padding space. This ensures that the snapshot content
// is deterministic. // is deterministic.
...@@ -664,20 +665,21 @@ class SeqTwoByteString ...@@ -664,20 +665,21 @@ class SeqTwoByteString
using Char = uint16_t; using Char = uint16_t;
// Dispatched behavior. // Dispatched behavior.
inline uint16_t Get(int index); inline uint16_t Get(int index) const;
inline void SeqTwoByteStringSet(int index, uint16_t value); inline void SeqTwoByteStringSet(int index, uint16_t value);
// Get the address of the characters in this string. // Get the address of the characters in this string.
inline Address GetCharsAddress(); inline Address GetCharsAddress() const;
// Get a pointer to the characters of the string. May only be called when a // Get a pointer to the characters of the string. May only be called when a
// SharedStringAccessGuard is not needed (i.e. on the main thread or on // SharedStringAccessGuard is not needed (i.e. on the main thread or on
// read-only strings). // read-only strings).
inline uc16* GetChars(const DisallowGarbageCollection& no_gc); inline uc16* GetChars(const DisallowGarbageCollection& no_gc) const;
// Get a pointer to the characters of the string. // Get a pointer to the characters of the string.
inline uc16* GetChars(const DisallowGarbageCollection& no_gc, inline uc16* GetChars(
const SharedStringAccessGuardIfNeeded& access_guard); const DisallowGarbageCollection& no_gc,
const SharedStringAccessGuardIfNeeded& access_guard) const;
// Clear uninitialized padding space. This ensures that the snapshot content // Clear uninitialized padding space. This ensures that the snapshot content
// is deterministic. // is deterministic.
...@@ -720,7 +722,7 @@ class ConsString : public TorqueGeneratedConsString<ConsString, String> { ...@@ -720,7 +722,7 @@ class ConsString : public TorqueGeneratedConsString<ConsString, String> {
inline Object unchecked_second(); inline Object unchecked_second();
// Dispatched behavior. // Dispatched behavior.
V8_EXPORT_PRIVATE uint16_t Get(int index); V8_EXPORT_PRIVATE uint16_t Get(int index) const;
// Minimum length for a cons string. // Minimum length for a cons string.
static const int kMinLength = 13; static const int kMinLength = 13;
...@@ -743,7 +745,7 @@ class ThinString : public TorqueGeneratedThinString<ThinString, String> { ...@@ -743,7 +745,7 @@ class ThinString : public TorqueGeneratedThinString<ThinString, String> {
public: public:
DECL_GETTER(unchecked_actual, HeapObject) DECL_GETTER(unchecked_actual, HeapObject)
V8_EXPORT_PRIVATE uint16_t Get(int index); V8_EXPORT_PRIVATE uint16_t Get(int index) const;
DECL_VERIFIER(ThinString) DECL_VERIFIER(ThinString)
...@@ -769,7 +771,7 @@ class SlicedString : public TorqueGeneratedSlicedString<SlicedString, String> { ...@@ -769,7 +771,7 @@ class SlicedString : public TorqueGeneratedSlicedString<SlicedString, String> {
inline void set_parent(String parent, inline void set_parent(String parent,
WriteBarrierMode mode = UPDATE_WRITE_BARRIER); WriteBarrierMode mode = UPDATE_WRITE_BARRIER);
// Dispatched behavior. // Dispatched behavior.
V8_EXPORT_PRIVATE uint16_t Get(int index); V8_EXPORT_PRIVATE uint16_t Get(int index) const;
// Minimum length for a sliced string. // Minimum length for a sliced string.
static const int kMinLength = 13; static const int kMinLength = 13;
...@@ -848,10 +850,10 @@ class ExternalOneByteString : public ExternalString { ...@@ -848,10 +850,10 @@ class ExternalOneByteString : public ExternalString {
// which the pointer cache has to be refreshed. // which the pointer cache has to be refreshed.
inline void update_data_cache(Isolate* isolate); inline void update_data_cache(Isolate* isolate);
inline const uint8_t* GetChars(); inline const uint8_t* GetChars() const;
// Dispatched behavior. // Dispatched behavior.
inline uint8_t Get(int index); inline uint8_t Get(int index) const;
DECL_CAST(ExternalOneByteString) DECL_CAST(ExternalOneByteString)
...@@ -894,10 +896,10 @@ class ExternalTwoByteString : public ExternalString { ...@@ -894,10 +896,10 @@ class ExternalTwoByteString : public ExternalString {
// which the pointer cache has to be refreshed. // which the pointer cache has to be refreshed.
inline void update_data_cache(Isolate* isolate); inline void update_data_cache(Isolate* isolate);
inline const uint16_t* GetChars(); inline const uint16_t* GetChars() const;
// Dispatched behavior. // Dispatched behavior.
inline uint16_t Get(int index); inline uint16_t Get(int index) const;
// For regexp code. // For regexp code.
inline const uint16_t* ExternalTwoByteStringGetData(unsigned start); inline const uint16_t* ExternalTwoByteStringGetData(unsigned start);
...@@ -927,9 +929,9 @@ class V8_EXPORT_PRIVATE FlatStringReader : public Relocatable { ...@@ -927,9 +929,9 @@ class V8_EXPORT_PRIVATE FlatStringReader : public Relocatable {
public: public:
FlatStringReader(Isolate* isolate, Handle<String> str); FlatStringReader(Isolate* isolate, Handle<String> str);
void PostGarbageCollection() override; void PostGarbageCollection() override;
inline uc32 Get(int index); inline uc32 Get(int index) const;
template <typename Char> template <typename Char>
inline Char Get(int index); inline Char Get(int index) const;
int length() { return length_; } int length() { return length_; }
private: private:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment